Skip to main content

Typed, auto-generated client for the OpenSwarm product-analytics ingest API.

Project description

swarm_analytics

A typed, auto-generated Python client for the OpenSwarm product-analytics ingest API. It is the single network egress the desktop FastAPI backend imports to send analytics — identity comes from a bearer token, payloads are validated against the exact pydantic models the server enforces, and delivery is fire-and-forget with background retry.

Why it's hard to call wrong

  • Identity is impossible to pass. No method takes install_id/user_id; the server resolves them from the token.
  • Per-request meta is auto-filled. ts and submission_id never appear in a signature — the transport stamps them (and reuses submission_id on every retry for idempotency).
  • Enums stay enums. status, action, role, etc. are Literals. A bad value raises pydantic.ValidationError synchronously, in your stack, before any network I/O.
  • Models are vendored verbatim from the service, so the client validates with the same schema the server uses.

Install

pip install ./sdk          # from the repo root

Usage

from swarm_analytics import AnalyticsClient, AgentMessage

# One-time bootstrap on first launch (unauthenticated, blocking)
token = AnalyticsClient.register(base_url="https://analytics.openswarm.ai", install_id=install_id)
# persist `token` in settings; reuse forever

client = AnalyticsClient(base_url="https://analytics.openswarm.ai", token=token)

client.events.app_lifecycle.opened(os="darwin", os_version="25.3.0", app_version="1.2.0")
client.events.agent.create(id="sess_123", name="Refactor auth", dashboard_id="dash_1")
client.events.agent.message(agent_id="sess_123", seq=0,
                            message=AgentMessage(id="m1", role="user", content="hello"))
client.events.onboarding.step(step_id="connect_provider", status="completed")
client.events.dashboard.event(dashboard_id="dash_1", action="create")
client.logs.write(tag="agent", subtag="tool", data={"name": "shell"})
client.identify.link_email(email="user@example.com")

# On shutdown
client.events.app_lifecycle.closed()
client.flush(timeout=2.0)
client.close()

Durability (optional)

By default events live in an in-memory queue and are lost if the process dies with deliveries pending. Pass a spool for crash/offline durability:

from swarm_analytics import SqliteSpool
client = AnalyticsClient(base_url=..., token=..., spool=SqliteSpool("service_spool.db"))

Opt-out

client = AnalyticsClient(base_url=..., token=..., mode="minimal")  # mutes product events; diagnostics still flow

Regenerating (auto-generated — do not hand-edit _generated/)

The models, route table, and namespaces under src/swarm_analytics/_generated/ are produced from the live service. Regenerate whenever the backend's ingest models or routes change:

PYTHONPATH=<repo_root> python sdk/generate.py

ROUTE_SPECS in generate.py (nice method name + category per endpoint) is the only human input; it is cross-checked against the live app, so a new or removed endpoint fails generation rather than drifting silently.

Drift check (CI)

PYTHONPATH=<repo_root> python sdk/generate.py --check

Exits non-zero if the committed _generated/ output is stale. The same guard runs as tests/test_drift.py.

Tests

cd sdk && PYTHONPATH=<repo_root> python -m pytest tests -q

Covers synchronous validation, meta auto-fill, identity-from-token, idempotent submission_id reuse across retries, opt-out gating, the drift check, and an end-to-end pass through the real FastAPI app.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarm_analytics-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarm_analytics-0.1.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file swarm_analytics-0.1.0.tar.gz.

File metadata

  • Download URL: swarm_analytics-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for swarm_analytics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 350295b34a9add636c6d2d7aa968d8730718e3311642c6050b457a3b5f568107
MD5 ab5f5ea34d7f19ae1c6127b13bcaebf2
BLAKE2b-256 2f86ee3616db5d129433b316611676174cc41b0c163d39f1fdc54ccd8907057b

See more details on using hashes here.

File details

Details for the file swarm_analytics-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swarm_analytics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 192b441ade9e9450dfb2a12409ae61c4ef3b67a2db11cd56e3404463cf05636b
MD5 14eda4c8a3f9c063b7e65e595d469c12
BLAKE2b-256 fc162b9d0f5455861b89b80b09cbed3f8882251fa675f7d41fda261045f48896

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page