Skip to main content

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

Metadata

Release files for mochi-analytics 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mochi-analytics 1.0.0
File Size Uploaded
mochi_analytics-1.0.0.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mochi-analytics 1.0.0
File Interpreter ABI Platform
mochi_analytics-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / mochi_analytics-1.0.0.tar.gz

Download URL mochi_analytics-1.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
12081f086d6d1d94aafe146520e17b4827274639fb02b94657ce77363743a8b1
BLAKE2b-256 checksum
How to use checksums
059203037154b29ac1de280e2d5e332e81eed1b047846cced592b4fca5312c87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / mochi_analytics-1.0.0-py3-none-any.whl

Download URL mochi_analytics-1.0.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7d59a93e729b198fb01af9170ce93e79919ec5a77f2c06117abbfd66cc37b44
BLAKE2b-256 checksum
How to use checksums
f3250322135f21a9d9d18460399a7db4709b068ce4d1c123176177759ed2da45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page