Metadata-Version: 2.5
Name: orbitspace-sdk
Version: 0.1.0
Summary: OrbitSpace sync and async REST/SSE application SDK
Project-URL: Homepage, https://developer.orbitspace.dev/en/sdk/
Project-URL: Documentation, https://docs.orbitspace.dev/en/developers/python-sdk/
Project-URL: Repository, https://github.com/orbitmesh-official/orbitspace-python-sdk
Project-URL: Issues, https://github.com/orbitmesh-official/orbitspace-python-sdk/issues
Author: OrbitSpace
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: attrs<27,>=25.3
Requires-Dist: httpx<0.29,>=0.28.1
Requires-Dist: python-dateutil<3,>=2.9
Description-Content-Type: text/markdown

# OrbitSpace Python SDK

Python 3.11+ application backend SDK with synchronous and asynchronous clients,
330 typed REST operations, OAuth, explicit Task interaction, SSE recovery and
verified downloads. Package: **orbitspace-sdk**; import namespace: **orbitspace**.
Requires Python **3.11 or later**.

| Documentation / 开发文档 | English | 中文 |
| --- | --- | --- |
| Developer Center / 开发者中心 | [Open](https://developer.orbitspace.dev/en/) | [打开](https://developer.orbitspace.dev/zh-CN/) |
| Python SDK handbook / Python 手册 | [Integration guide](https://docs.orbitspace.dev/en/developers/python-sdk/) | [接入指南](https://docs.orbitspace.dev/zh-CN/developers/python-sdk/) |
| API reference / API 参考 | [Public REST API](https://developer.orbitspace.dev/en/reference/tasks/) | [公开 REST API](https://developer.orbitspace.dev/zh-CN/reference/tasks/) |
| Authentication / 认证 | [API Tokens & OAuth](https://docs.orbitspace.dev/en/integrations/authentication/) | [API Token 与 OAuth](https://docs.orbitspace.dev/zh-CN/integrations/authentication/) |

## Install a published release

Install version **0.1.0** after it is available on
[PyPI](https://pypi.org/project/orbitspace-sdk/):

```sh
python -m pip install orbitspace-sdk==0.1.0
```

During initial publication or when working with an unreleased checkout, use the
source installation below. A version declared in the source tree alone does not
prove that its PyPI release has completed.

## Build from source

The SDK-only public distribution repository is
[orbitspace-python-sdk](https://github.com/orbitmesh-official/orbitspace-python-sdk).
Install from the public repository using Python 3.11+ and
a dedicated virtual environment:

```sh
git clone https://github.com/orbitmesh-official/orbitspace-python-sdk.git
cd orbitspace-python-sdk
python -m venv .venv
. .venv/bin/activate
python -m pip install .
```

Consumers import `orbitspace`. They do not need a generator, protobuf, Buf or
an application framework. Tagged releases are published through GitHub OIDC
Trusted Publishing; consumers do not need PyPI publishing credentials.

## Sync and async clients

```python
from orbitspace import OrbitSpaceClient, models

with OrbitSpaceClient(token=api_token_from_secret_store, tenant_id=tenant_id) as client:
    task = client.tasks.create(models.CreateTaskRequest(
        workspace_id=workspace_id,
        workspace_agent_binding_id=binding_id,
        input="Summarize the supplied document.",
        idempotency_key=durable_business_job_key,
    ))
    result = client.tasks.wait(task.id, timeout=600)
    # Inspect result.state: waiting_input, waiting_approval and paused are not success.
```

Use `async with AsyncOrbitSpaceClient(...)` and `await client.tasks.create(...)`
for asyncio applications. Async streams use `async for`; sync streams are ordinary
iterators. Close streams explicitly when stopping early, and close the client.
The sync facade uses a dedicated I/O loop for the same bounded async transport;
closing a local client/stream never cancels the remote Task. Each client owns
its dedicated token provider; do not share one across clients/event loops.
See the runnable [backend example](examples/task.py).

## OAuth and explicit writes

Use `ClientCredentials(token_url, client_id, client_secret=secret, scope=scope)` as
`token_provider`, instead of `token`. Supply the issuer's actual HTTPS token URL.
`client_secret_basic`, `client_secret_post` and `private_key_jwt` are supported;
for the latter, provide an `assertion(audience)` signer. Secrets never belong in
source code, public browser bundles or model-provider configuration.

Issuance is single-flight per provider; cancelling one waiter leaves others
running. Expiring tokens renew early; responses without expiry are not cached
long-term. `invalidate()` discards cached credentials and prevents stale in-flight
issuance from restoring the old cache. Dedicated providers close with the client.

`tasks.input_requests`, `get_input` and `reply_input` use the existing input
request. Replies require a persistent idempotency key and the exact decimal
`expected_state_version`. Read a fresh Task before `resume`, `pause`, `retry` or
`cancel`. SDKs never automatically answer, approve or resume. Writes are never
automatically replayed. Scopes do not replace tenant/project authorization.

## Streams, deadlines and errors

`tasks`, `invocations` and `goals` expose `watch`, `observe` and `wait`. A finite
`timeout` is required. `observe` reads authoritative snapshots after events,
with a minimum interval, and performs no idle polling. `wait` returns when an
intervention or terminal state is reached. Local cancellation stops local I/O.

Use `StreamOptions(after=cursor, committed_cursor=load_committed_cursor)` for
recovery. Commit effects and cursor atomically in business storage; observation
alone is not acknowledgement. Reconnect reads the committed supplier, not the
last observed event. Without a supplier it reuses the initial cursor: tolerate
duplicates. Incomplete EOF frames are discarded; UTF-8 and frame limits are
checked. History gaps remain explicit errors, never a silent jump to live data.

API requests have a total deadline (30 seconds by default), including body reads.
Only GET/HEAD transient failures have bounded retries. Redirects, cookies,
implicit environment authentication and cross-origin token forwarding are
blocked. `ApiError` exposes `status`, `code`, `request_id`; default exception
messages omit response bodies, credentials and signed URLs.

## Verified artifact downloads

```python
result = client.artifacts.download_file(
    artifact_id, destination, max_bytes=32 << 20, timeout=120,
)
```

Downloads use a separate credential-free client, check receipt expiry, exact size,
byte limits and SHA-256, then atomically replace the destination. Failures remove
private staging files and preserve the previous file. The default destination
is the API artifact-download prefix; S3/CDN origins need explicit
`Destination(origin, path_prefix)` entries. Redirects are not followed.

## Full typed API

```python
from orbitspace.generated.api.task_service import task_service_get_task
resource = task_service_get_task.sync(client=client.api, id=task_id)
# Async: await task_service_get_task.asyncio(client=client.api, id=task_id)
```

Generated operations use the same credential boundary. `orbitspace.models`
exports typed wire models. `UNSET`, explicit null, empty lists, unknown string
enums and large decimal version strings remain distinct. The public contract
is embedded in the wheel. Raw operation modules expose the complete admitted
application API, including Skill/Registry resources; Worker/Host administration
and secret leasing are excluded.

This SDK does not install Runtimes, perform interactive OIDC/PKCE login or
implement an application business ledger. Use an established login client and
the separate Runtime/domain-tool contracts for those integrations.

## Development

Use the pinned development requirements and run `scripts/qualify.sh`. Generation
uses openapi-python-client 0.28.3 against a separate open-enum adapter; canonical
OpenAPI 3.1 is unchanged. Both sync/async generated operations and typed sync
facades are reproduced during qualification. SDK source and wheel/sdist release
versions are independent of API, Runtime and website versions.

Apache-2.0. See LICENSE.
