Python SDK for Aptabase analytics
Project description
Aptabase Python SDK
Python SDK for Aptabase - privacy-first analytics for mobile, desktop and web applications.
Features
- 🚀 Fully async - Built with
httpxandasyncio - 🔒 Privacy-first - No personal data collection
- 🏃 Modern Python - Requires Python 3.11+
- 📦 Type-safe - Full typing support
- 🔄 Auto-batching - Efficient event batching and flushing
- ⚡ Lightweight - Minimal dependencies
Installation
uv add aptabase
# or
pip install aptabase
Quick Start
import asyncio
from aptabase import Aptabase
async def main():
async with Aptabase("A-EU-1234567890") as client:
# Track a simple event
await client.track("app_started")
# Track an event with properties
await client.track("user_action", {
"action": "button_click",
"button_id": "login",
"screen": "home"
})
# Events are automatically flushed, but you can force it
await client.flush()
asyncio.run(main())
Configuration
client = Aptabase(
app_key="A-EU-1234567890", # Your Aptabase app key
app_version="1.2.3", # Your app version
is_debug=False, # Enable debug mode
max_batch_size=25, # Max events per batch (max 25)
flush_interval=10.0, # Auto-flush interval in seconds
timeout=30.0 # HTTP timeout in seconds
)
App Key Format
Your app key determines the server region:
A-EU-*- European serversA-US-*- US servers
Get your app key from the Aptabase dashboard.
Event Tracking
Simple Events
await client.track("page_view")
Events with Properties
await client.track("purchase", {
"product_id": "abc123",
"price": 29.99,
"currency": "USD"
})
Session Management
# Set a custom session ID
client.set_session_id("my-custom-session-id")
# Track events with specific session
await client.track("login", session_id="user-session-123")
Context Manager vs Manual Lifecycle
Recommended: Context Manager
async with Aptabase("A-EU-1234567890") as client:
await client.track("event")
# Automatically handles start/stop and flushing
Manual Lifecycle
client = Aptabase("A-EU-1234567890")
await client.start()
try:
await client.track("event")
finally:
await client.stop() # Ensures all events are flushed
Error Handling
from aptabase import Aptabase, AptabaseError, NetworkError
try:
async with Aptabase("A-EU-1234567890") as client:
await client.track("event")
except NetworkError as e:
print(f"Network error: {e}, status: {e.status_code}")
except AptabaseError as e:
print(f"Aptabase error: {e}")
Development
Install development dependencies:
uv sync --dev
Run tests:
uv run pytest
Code formatting:
uv run black .
uv run ruff check .
Type checking:
uv run mypy .
License
MIT License - see LICENSE file for details.
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
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 aptabase-0.0.1.tar.gz.
File metadata
- Download URL: aptabase-0.0.1.tar.gz
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb3deb3aa98246d3f011403ae50acf68d0c3847c384c3b537d8a0cc10ac73b20
|
|
| MD5 |
ff7cc6e61bbc06f8dc96b6bad669f781
|
|
| BLAKE2b-256 |
91ae84c53e23a482099c2d0bcc39e9aa42905ab6704b9a17d11dfd978107ac45
|
Provenance
The following attestation bundles were made for aptabase-0.0.1.tar.gz:
Publisher:
cd.yml on aptabase/aptabase-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aptabase-0.0.1.tar.gz -
Subject digest:
eb3deb3aa98246d3f011403ae50acf68d0c3847c384c3b537d8a0cc10ac73b20 - Sigstore transparency entry: 761549822
- Sigstore integration time:
-
Permalink:
aptabase/aptabase-python@c42e2c582f07d8dade399fa1a626765c613f6163 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aptabase
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@c42e2c582f07d8dade399fa1a626765c613f6163 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aptabase-0.0.1-py3-none-any.whl.
File metadata
- Download URL: aptabase-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5656176632b316354f28fd5abb4edd498b63ad2b69ddda1f7ebd4a9303feb5dc
|
|
| MD5 |
9adca4413b3039bcb191664c53fad205
|
|
| BLAKE2b-256 |
5854905f2bdfbfe415ce474509988cad02a897814ee7c6d6bd90785160531c12
|
Provenance
The following attestation bundles were made for aptabase-0.0.1-py3-none-any.whl:
Publisher:
cd.yml on aptabase/aptabase-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aptabase-0.0.1-py3-none-any.whl -
Subject digest:
5656176632b316354f28fd5abb4edd498b63ad2b69ddda1f7ebd4a9303feb5dc - Sigstore transparency entry: 761549851
- Sigstore integration time:
-
Permalink:
aptabase/aptabase-python@c42e2c582f07d8dade399fa1a626765c613f6163 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aptabase
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@c42e2c582f07d8dade399fa1a626765c613f6163 -
Trigger Event:
push
-
Statement type: