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_errorcallback, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12081f086d6d1d94aafe146520e17b4827274639fb02b94657ce77363743a8b1
|
|
| MD5 |
bca27cd46053fb44fd7be30d2696c6b4
|
|
| BLAKE2b-256 |
059203037154b29ac1de280e2d5e332e81eed1b047846cced592b4fca5312c87
|
Provenance
The following attestation bundles were made for mochi_analytics-1.0.0.tar.gz:
Publisher:
release-please.yml on mochi-analytics/mochi-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mochi_analytics-1.0.0.tar.gz -
Subject digest:
12081f086d6d1d94aafe146520e17b4827274639fb02b94657ce77363743a8b1 - Sigstore transparency entry: 2125561297
- Sigstore integration time:
-
Permalink:
mochi-analytics/mochi-py@0c15c00fbde7562c4cf062656bbfa97a3bf6e0e3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mochi-analytics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@0c15c00fbde7562c4cf062656bbfa97a3bf6e0e3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mochi_analytics-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mochi_analytics-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d59a93e729b198fb01af9170ce93e79919ec5a77f2c06117abbfd66cc37b44
|
|
| MD5 |
1a9d8bb444d318775c22fd1d05726053
|
|
| BLAKE2b-256 |
f3250322135f21a9d9d18460399a7db4709b068ce4d1c123176177759ed2da45
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mochi_analytics-1.0.0-py3-none-any.whl -
Subject digest:
e7d59a93e729b198fb01af9170ce93e79919ec5a77f2c06117abbfd66cc37b44 - Sigstore transparency entry: 2125561376
- Sigstore integration time:
-
Permalink:
mochi-analytics/mochi-py@0c15c00fbde7562c4cf062656bbfa97a3bf6e0e3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mochi-analytics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@0c15c00fbde7562c4cf062656bbfa97a3bf6e0e3 -
Trigger Event:
push
-
Statement type: