Metadata-Version: 2.4
Name: celedon-davinci-sdk
Version: 0.2.0
Summary: Official Python SDK for the Davinci API
Author-email: "Celedon Solutions, Inc" <support@celedon.solutions>
License-Expression: MIT
Project-URL: Homepage, https://celedon.solutions/davinci
Project-URL: Documentation, https://docs.davinci-app.com/pages/api/introduction
Project-URL: Repository, https://github.com/Celedon-Solutions
Keywords: davinci,celedon,sdk,api
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0.0
Requires-Dist: python-dateutil>=2.8.2
Requires-Dist: typing-extensions>=4.7.0
Requires-Dist: urllib3>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"
Dynamic: license-file

# Davinci Python SDK

Official Python SDK for Davinci's public API.

## Install

```bash
pip install celedon-davinci-sdk
```

## Quick Start

```python
from davinci_sdk import DavinciClient

with DavinciClient(api_key="dav_ak_live_...", base_url="https://davinci-app.com") as client:
    project = client.projects.create(name="Spacecraft")
    opened = client.projects.open(project.id, branch="main")
    print(opened.branch_name, opened.already_loaded)
    client.projects.close(project.id)
```

For a full lifecycle walkthrough:

```bash
DAVINCI_API_KEY=dav_ak_live_... python examples/project_lifecycle.py
```

## Namespaces

| Namespace | What it covers |
|---|---|
| `client.projects` | Project lifecycle, branches and packages listings, file listing and download |
| `client.organizations` | Read-only discovery of organizations available to team operations |
| `client.content` | The parts tree, individual objects, adding or deleting objects, and exporting an object to a file |
| `client.branches` | Creating and deleting branches, committing, uncommitted changes, object history |
| `client.sessions` | Sessions, and through them the data plane for file transfer and the agent |
| `client.cards` | Flat Task Card search, lifecycle, details, comments, assignments, tags, and links |
| `client.card_tags` | Project Task Card tag catalog |
| `client.teams` | Operational teams, statuses, sprints, boards, reports, and charts |

The agile workflow example uses an existing project and team, creates temporary
card-planning data, reads a report, and cleans up:

```bash
DAVINCI_API_KEY=dav_ak_live_... \
DAVINCI_PROJECT_ID=... \
DAVINCI_TEAM_ID=... \
python examples/agile_workflow.py
```

Set `DAVINCI_ORG_ID` when the team is not in the first organization returned by
`client.organizations.list()`.

`content` and `branches` reach the running project, so they open it if it is
closed and they see uncommitted work. ``projects.list_files`` reads the saved
snapshot instead, so it works on a closed project and does not show a file
attached since the last save.

Every object needs a parent, its own `parent` or the request's `parent_id`.
`MODEL_PACKAGE_ID` is the top of the model and `LIBRARY_PACKAGE_ID` the Library;
an object with no parent, or a parent that cannot hold it, is refused.

```python
import uuid
from davinci_sdk import MODEL_PACKAGE_ID

client.content.add_objects(project.id, {
    str(uuid.uuid4()): {"type": "requirement", "name": "Dry mass under 500 kg"},
}, parent_id=MODEL_PACKAGE_ID)
result = client.branches.commit(project.id, "main", "Seed")
history = client.branches.get_object_history(project.id, object_id)
```

`content.export_object` produces the file the editor's Export menu would, such
as a document as PDF or DOCX, and saves it to the project. It runs on the
server, so nobody needs the project open:

```python
exported = client.content.export_object(project.id, document_id, format="pdf")
print(exported.page_count)
pdf = client.projects.download_file(project.id, exported.file.id)
```

Project-card search uses a bounded opaque cursor. `include_no_team` and
`include_unassigned` OR the corresponding null case with selected IDs inside
that facet; separate facets remain ANDed. Team card lists, comments, and history
use offset pagination:

```python
page = client.cards.search(
    project_id,
    state="open",
    include_no_team=True,
    include_unassigned=True,
    sort="created_desc",
    limit=100,
)
if page.meta.next_cursor:
    next_page = client.cards.search(
        project_id,
        limit=page.meta.limit,
        cursor=page.meta.next_cursor,
    )

comments = client.cards.comments.list(project_id, card_id, limit=50, offset=0)
history = client.cards.history.list(project_id, card_id, limit=50, offset=0)
overview = client.teams.get_overview(org_id, team_id)
completed = client.teams.sprints.list_completed(org_id, team_id, limit=25)
available = client.teams.cards.search_available(
    org_id,
    team_id,
    query="bearing",
    project_ids=[project_id],
    limit=50,
)
```

## Safe create retries

Project, card, comment, catalog-tag, team, team-status, and
team-sprint creates accept `idempotency_key`. Reuse the same key only when
retrying the same create after a timeout or network failure; the server returns
the original result instead of repeating the mutation. Use a fresh key for a
new create. Reusing a key with different request data returns
`IDEMPOTENCY_KEY_REUSED`, and a create still in progress returns
`IDEMPOTENCY_REQUEST_IN_PROGRESS`.

```python
card = client.cards.create(
    project_id,
    "Inspect propulsion mount",
    resolution=None,
    idempotency_key="workflow-42-card",
)
client.cards.update(
    project_id,
    str(card.card.id),
    description="Ready for review",
    is_open=False,
    resolution="Inspection complete",
    expected_history_head_id=str(card.history_head_id),
)
```

Keys are scoped to the authenticated actor and may contain at most 255
characters. Supplying a key does not make unrelated mutations safe to retry.

## The agent

A session is where the agent lives, because the agent acts on the open project a
session holds. ``send_message`` returns as soon as the prompt is taken, so
waiting for the result is a separate step:

```python
with client.sessions.create(project.id, branch="main") as session:
    session.send_message("Add a mounting bracket for the avionics tray")
    state = session.wait_until_done()      # polls to a terminal status
    for entry in session.messages().messages:
        print(entry.role, entry.text)
```

A terminal status is not necessarily a good one — ``failed`` is terminal, and so
is the ``paused`` a ``stop()`` produces — so read the status rather than assuming
success. To run one tool with no model deciding anything, ``invoke_tool`` is
deterministic and spends no LLM credits:

```python
session.invoke_tool(toolbox="Core", tool="MakePackage", params={"name": "Avionics"})
```

## Authentication

Use a Davinci personal access token. Reads require the `projects:read` scope,
`open`/`close`, file deletes, object writes, commits, and branch creation
require `projects:write`, and create/update/delete plus branch deletion require
`projects:manage`. Sessions need `sessions:manage`, and directing the agent needs
`agent:message`, which the project scopes do not confer.

Task Cards use a separate `cards:read` → `cards:write` → `cards:manage`
scope ladder. Operational teams use `teams:read` → `teams:write` →
`teams:manage`. Board card mutations require both `teams:write` and
`cards:write`. Scopes only narrow access: every request is also checked against
the token owner's current project, organization, and team permissions.
The `manage` names describe the largest published API capability bundle in each
ladder; they do not grant every domain permission or bypass live role-based
authorization.

Card user links currently support the `participant` relation, card-to-card links
support `relates_to`, `depends_on`, and `dependency_of`, and object links use
`related`. Creating an object link additionally requires `projects:read` and
live `models:read`; the server verifies the object in the selected Project
branch and stores canonical name/type metadata rather than trusting caller
labels. Replacing a card's complete tag set accepts at most 50 tags.

Team membership, invitations, self-leave, and accepted ownership transfer
remain browser-only and are not part of the SDK.

Team board reads include effective action capabilities. A board Card is either
`full` when the credential and live Project role both allow `cards:read`, or a
bounded `team-board-summary` containing operational title, placement, lifecycle,
assignee, and tag data. Description and resolution are omitted from summaries.
Reports and chart routes additionally require the live
`teams:sprints:analysis:read` permission.

An optional initial assignee on Card creation is validated and written in the
same transaction as the Card and history. Sprint deletion rejects active or
non-empty sprints; complete the sprint and move or remove every Card first.
Team Card creation also accepts `assignee_ids`, `tag_ids`, and `card_links`;
those relationships, Team placement, mentions, and history commit atomically.
Available-card search is cursor-paginated across already-linked writable
Projects and excludes Cards already on the Team.

Every card-affecting method accepts `expected_history_head_id`; bulk status,
sprint, tag, and team methods accept `expected_history_head_ids`. Stale writes
raise `DavinciError` with code `CARD_HISTORY_CONFLICT` and preserve the
server-provided current head and recent activity. Team workflow statuses expose
`close_mode` (`off`, deprecated legacy `manual`, or `automatic`), and
`client.teams.statuses.close_all(...)` transactionally closes all open cards in
any column. No status transition reopens a card or changes
another team's placement.

`is_open` is the project-global card State; each placement has an independent
team workflow Status. Closing changes State for every team without moving any
Status. Optional Markdown `resolution` survives reopen. Search rows expose
ordered `team_statuses`; card-list icons use the first status surviving active
team/status filters and remain neutral when Closed or no eligible status exists.
Creating a Task Card tag without `color` uses `#FF9900`.

Opening a project with an API key returns lifecycle confirmation only: the
`url` and `server_token` a browser receives are withheld, so a key controls the
lifecycle without reaching live project data.

## Development

Generated OpenAPI client code lives in `generated-client/`; the public SDK
wrapper lives in `davinci_sdk/`.

```bash
python -m pip install -e ".[dev]"
black --check davinci_sdk tests examples
pytest
mypy davinci_sdk
python -m build
python -m twine check dist/*
```

Full HTTP API docs live at https://docs.davinci-app.com/pages/api/introduction.
