Metadata-Version: 2.5
Name: bytesmap
Version: 0.1.1
Summary: The official BytesMap Python SDK: workspace API operations and event ingestion.
Project-URL: Homepage, https://bytesmap.com
Project-URL: Repository, https://github.com/oblien/bytesmap
Project-URL: Documentation, https://github.com/oblien/bytesmap/tree/main/packages/python
Project-URL: Issues, https://github.com/oblien/bytesmap/issues
Author: BytesMap
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: analytics,bytesmap,database,events,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
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: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# BytesMap for Python

The official Python 3.11+ SDK for the BytesMap workspace API and append-only event
ingestion. It has no runtime dependencies and uses the standard library with
verified TLS. All 240 API methods are generated from BytesMap's shared operation
catalogue, with Python names and keyword arguments.

```sh
pip install bytesmap
```

## Send events

Create a dataset and an ingestion key in **Events → Connect application**. Set
`BYTESMAP_EVENTS_URL`, `BYTESMAP_EVENT_DATASET`, and `BYTESMAP_EVENT_TOKEN`, then:

```python
import os
from bytesmap import EventClient

with EventClient(
    endpoint=os.environ["BYTESMAP_EVENTS_URL"],
    dataset=os.environ["BYTESMAP_EVENT_DATASET"],
    token=os.environ["BYTESMAP_EVENT_TOKEN"],
    namespace="production",
    group="application",
) as events:
    accepted = events.emit("app.started")
    # Declare durationMs on the dataset before sending this dimension.
    events.emit(
        "request.finished", dimensions={"durationMs": 120}, data={"route": "/orders"}
    )
```

`emit()` waits for durable acceptance. There is no background buffer or shutdown
flush. IDs, UTC timestamps and schema version 1 are supplied automatically.
`events.scope(dimensions={"userId": "user_42"})` snapshots request context while
sharing the transport. Declare dimension names and types on the dataset first;
full JSON belongs in `data`. Pass `error=exception` to capture its name, message,
stack and explicit cause.

Use `send([EventDraft("app.started"), ...])` for a batch. Limits match the server:
1,000 events, 1 MiB per batch, 64 dimensions and 64 KiB of dimensions/data per event.
Numbers must fit the JavaScript safe range. HTTPS is required. Local testing on
HTTP loopback requires explicit `allow_plaintext_loopback=True`.

Network errors, HTTP 408/429/5xx and invalid acceptance receipts retry with the
same batch identity and bytes (default five attempts). Other HTTP errors fail
immediately. `EventDeliveryError.batch` returns the original payload for
`events.retry(error.batch)`. An unconfirmed send may already have been accepted;
preserve its batch identity when retrying. `Retry-After` above one minute returns
`retry_later` so the application can schedule its retry.

## Workspace API

```python
import os
from bytesmap import BytesMapClient, CallOptions

with BytesMapClient(
    base_url="https://api.example.com",
    token=os.environ["BYTESMAP_API_TOKEN"],
    project_id="project-id",
) as client:
    dashboards = client.dashboards.list()
    result = client.queries.run(id="saved-query-id")
    workspace = client.scope("workspace-id")
    workspace.sources.list(call_options=CallOptions(project_id="another-project"))
```

API and event ingestion keys are separate credentials. Keep workspace API keys on
your server. Scopes cannot widen a key's server-enforced permissions. Modules and
methods use `snake_case` (`client.event_destinations.list()`); keyword arguments
are mapped to the wire contract's field names (`destination_id` → `destinationId`).
Pass a dictionary with original wire field names for nested payloads:

```python
client.dashboards.update({"id": "dashboard-id", "folderId": None})
client.invoke("queries.run", {"id": "saved-query-id", "params": {"customer": "id"}})
```

Omitted fields stay omitted; `None` sends explicit JSON null. Methods return public
JSON values (dicts, lists and scalars). `BytesMapError` exposes `code`, `params` and
`status`; its string representation contains only the error code. Export methods
return `filename`, `contentType` and `contentBase64`.

API mutations are never automatically retried. All requests reject redirects and
use a finite timeout. A `token` callback supports rotating credentials; a
`project_id` callback supports current project selection. Project selection is
captured before the token callback. Closing a scope never closes its parent;
closing the parent makes its scopes unavailable.

Clients are synchronous. In async applications, use `asyncio.to_thread` around
calls; cancelling that await does not cancel the underlying HTTP request, which
remains bounded by its timeout. An optional `transport` implementing the exported
`Transport` protocol supports host-owned HTTP clients and tests; the caller owns
its lifetime and must disable redirects and retain TLS verification.

## Development

```sh
bun --no-env-file scripts/generate-python-sdk.ts
bun --no-env-file scripts/generate-python-sdk.ts --check
PYTHONPATH=packages/python/src python3 -m unittest discover -s packages/python/tests -v
python3 -m build packages/python
```

Generated catalogue files are committed. Regenerate them when the shared operation
catalogue or event limits change. Python releases are independent of npm and NuGet.
