Skip to main content

Official SKAWR Analytics SDK for Python — server-side event tracking.

Project description

skawr-analytics (Python)

Server-side SDK for SKAWR Analytics. Stateless, pluggable HTTP backend, type-hinted, Python 3.9+.

Install

pip install skawr-analytics
# Or with the default `requests` backend bundled:
pip install 'skawr-analytics[requests]'

Quickstart

from skawr_analytics import Skawr

skawr = Skawr(api_key="ska_xxxxxxxxxxxx")

# In your request handler:
skawr.track(
    "order_placed",
    user_id=request.user.id,
    properties={"value": 99.50, "currency": "SAR"},
)

# On login:
skawr.identify(
    user_id="u_42",
    anonymous_id=request.cookies.get("skawr_anon"),
    properties={"plan": "pro"},
)

Configuration

Skawr(
    api_key="ska_...",                                # required
    endpoint="https://analytics-api.skawr.com",        # override
    timeout=5.0,                                       # seconds
    default_properties={"app": "api", "env": "prod"},  # merged into every event
    http_post=my_async_post,                           # plug in httpx, custom transport, mocks
)

API

skawr.track(
    event_name,
    user_id=None,
    anonymous_id=None,
    session_id=None,
    properties=None,
    timestamp=None,                                    # datetime / float / str / None
    page_url=None,
    referrer_url=None,
    utm_source=None,
    utm_medium=None,
    utm_campaign=None,
) -> int  # HTTP status

skawr.identify(user_id, anonymous_id, properties=None) -> int

timestamp accepts datetime (naive treated as UTC), POSIX float, or ISO-8601 string. Defaults to datetime.now(UTC).

Custom HTTP backend

Pass any callable with signature (url, headers, body) -> response_with_status_code. Useful for:

  • httpx — for async or HTTP/2:
    import httpx
    client = httpx.Client(timeout=5.0)
    def post(url, headers, body):
        return client.post(url, headers=headers, content=body)
    Skawr(api_key="...", http_post=post)
    
  • Tests — record requests, return canned responses.
  • Custom retry / queue — wrap a worker that buffers and retries on failure.

Why server-side?

  • Trusted user_ids. Browser clients can't be trusted with revenue events; do those server-side.
  • Backend-only events. Webhook receipts, payment confirmations, scheduled jobs.
  • Defense-in-depth. Send the same event from both browser and server; dedupe later.

Development

pip install -e '.[dev]'
pytest
ruff check src
mypy src

License

MIT.

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

skawr_analytics-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

skawr_analytics-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: skawr_analytics-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for skawr_analytics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 74beb40df99d10d730f8c8e9f41047f08a12d11ec553b631a71e8c1da4c0d115
MD5 beca04d628d6fb015c14d369c6371808
BLAKE2b-256 2daa8d9090f14146f67b7ead30d21384aabdd6996cefd9a29732478b7cd10128

See more details on using hashes here.

Provenance

The following attestation bundles were made for skawr_analytics-0.1.0.tar.gz:

Publisher: publish-python-sdk.yml on LuqtahTech/skawr-analytics

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

File details

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

File metadata

File hashes

Hashes for skawr_analytics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0c81c645f32d3f147309c4af19c6e1df8cf110ba18d182207a12cdfcf7cf486
MD5 4ffe004f3bd0b964940830e48c3c9fea
BLAKE2b-256 1505a3afb1d0ac77cad007b1607cbe463b10142067832ef22a4023764827dd47

See more details on using hashes here.

Provenance

The following attestation bundles were made for skawr_analytics-0.1.0-py3-none-any.whl:

Publisher: publish-python-sdk.yml on LuqtahTech/skawr-analytics

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