Skip to main content

Unisights Python SDK provides a lightweight event collection endpoint for Python web frameworks.

Project description

Unisights Python SDK

Unisights Python SDK provides a lightweight event collection endpoint for Python web frameworks. It allows your backend to receive analytics events from the Unisights client SDK and process them using a custom handler.

The package exposes a single POST API endpoint that receives event payloads and forwards them to your handler for processing.

Supported frameworks:

  • FastAPI
  • Flask
  • Django
  • ASGI-compatible frameworks (Starlette, Quart, etc.)

Features

  • Simple event ingestion endpoint
  • Works with multiple Python frameworks
  • Async + sync handler support
  • Framework-agnostic core
  • Easy integration with analytics pipelines (Kafka, DB, queue, etc.)

Installation

pip install unisights

Event Payload Example

The endpoint expects a JSON payload.

{
  "type": "event",
  "name": "page_view",
  "session_id": "abc123",
  "timestamp": 1710000000,
  "data": {
    "url": "/home",
    "referrer": "google.com"
  }
}

FastAPI Integration

from fastapi import FastAPI
from unisights.fastapi import unisights_fastapi

app = FastAPI()

async def handler(payload, request):
    print(payload)

app.include_router(
    unisights_fastapi("/collect/event", handler)
)

Start server:

uvicorn main:app --reload

Endpoint:

POST /collect/event

Flask Integration

from flask import Flask
from unisights.flask import unisights_flask

app = Flask(__name__)

async def handler(payload, request):
    print(payload)

app.register_blueprint(
    unisights_flask("/collect/event", handler)
)

app.run()

Endpoint:

POST /collect/event

Django Integration

Add the route in your Django project.

from django.urls import path
from unisights.django import unisights_django

async def handler(payload, request):
    print(payload)

urlpatterns = [
    path("collect/event", unisights_django(handler))
]

Endpoint:

POST /collect/event

Using with Message Queues or Databases

Your handler can forward events to any system.

Example: Kafka

async def handler(payload, request):
    kafka_producer.send("analytics-events", payload)

Example: Save to database

async def handler(payload, request):
    db.events.insert_one(payload)

Project Structure

unisights/
├── collector.py
├── fastapi.py
├── flask.py
├── django.py
└── asgi.py
  • collector.py → Core event processor
  • fastapi.py → FastAPI adapter
  • flask.py → Flask adapter
  • django.py → Django adapter
  • asgi.py → Generic ASGI middleware

Development

Clone repository:

git clone https://github.com/pradeeparul/unisights
cd unisights-python

Install dependencies:

pip install -e .

Build package:

python -m build

Publish to PyPI:

twine upload dist/*

License

MIT License


Links

GitHub https://github.com/pradeeparul/unisights

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

unisights-0.0.1b2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file unisights-0.0.1b2-py3-none-any.whl.

File metadata

  • Download URL: unisights-0.0.1b2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for unisights-0.0.1b2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3503a7b63dcccc62085b0529c8370e08d2d76f9605f2e136d2f47b6dc831021
MD5 a14e02e93d4ab403a48469eefe86966d
BLAKE2b-256 b58f855f6f35c71e2ae5efd4dffd8f4eb1e3fa302f4ccc8f8a72edf4ea54de73

See more details on using hashes here.

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