Skip to main content

Core client for Mochi - self-hosted analytics for Discord bots

Project description

mochi-analytics

Core client for Mochi — self-hosted analytics for Discord bots. Asyncio-native, batching, and non-blocking: track() never blocks or raises into your bot.

Install

pip install mochi-analytics

Usage

from mochi_analytics import MochiClient, MochiEvent, MochiSnapshot

mochi = MochiClient(url="https://mochi.example.com", api_key="mochi_sk_...")

# Queue events — sent in the background, batched.
mochi.track(MochiEvent(type="command", name="play", user_id="123"))
mochi.track_command("play", guild_id="456")

# Send a health snapshot immediately.
await mochi.snapshot(MochiSnapshot(guild_count=1204, ws_ping_ms=38))

# On shutdown, flush anything still queued.
await mochi.shutdown()

Design guarantees

  • Events are batched (flushed every 5 s or 100 events) and sent in the background — track() never blocks or raises.
  • Transient failures (429 / 5xx / network) retry with exponential backoff; the queue is bounded (oldest dropped first), so a dead Mochi instance can never leak memory or crash the bot.
  • Errors are routed to the optional on_error callback, never raised.

Options

Argument Default Notes
flush_interval 5.0 Seconds between background flushes.
max_batch_size 100 Events per request (server limit is 100).
max_queue_size 10000 Events beyond this are dropped oldest-first.
max_retries 3 Retry attempts for retryable failures.
on_error no-op Callable[[Exception], None] for dropped/failed sends.
transport aiohttp Injectable async (url, body) -> (status, text) for testing.

License

Apache-2.0

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

mochi_analytics-1.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

mochi_analytics-1.0.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file mochi_analytics-1.0.0.tar.gz.

File metadata

  • Download URL: mochi_analytics-1.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mochi_analytics-1.0.0.tar.gz
Algorithm Hash digest
SHA256 12081f086d6d1d94aafe146520e17b4827274639fb02b94657ce77363743a8b1
MD5 bca27cd46053fb44fd7be30d2696c6b4
BLAKE2b-256 059203037154b29ac1de280e2d5e332e81eed1b047846cced592b4fca5312c87

See more details on using hashes here.

Provenance

The following attestation bundles were made for mochi_analytics-1.0.0.tar.gz:

Publisher: release-please.yml on mochi-analytics/mochi-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mochi_analytics-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mochi_analytics-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7d59a93e729b198fb01af9170ce93e79919ec5a77f2c06117abbfd66cc37b44
MD5 1a9d8bb444d318775c22fd1d05726053
BLAKE2b-256 f3250322135f21a9d9d18460399a7db4709b068ce4d1c123176177759ed2da45

See more details on using hashes here.

Provenance

The following attestation bundles were made for mochi_analytics-1.0.0-py3-none-any.whl:

Publisher: release-please.yml on mochi-analytics/mochi-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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