Skip to main content

Official Klyna SDK for Python — Flask, FastAPI, Django, Starlette middleware

Project description

klyna

Official Klyna SDK for Python. Automatically captures HTTP request metrics and sends them to the Klyna platform. Zero external dependencies — pure Python stdlib.

Installation

pip install klyna

Quick Start

FastAPI / Starlette (ASGI)

from fastapi import FastAPI
from klyna import KlynaASGIMiddleware, KlynaConfig

app = FastAPI()
config = KlynaConfig(api_key='sk_live_...')

# Wraps FastAPI, Starlette, or Django ASGI
app = KlynaASGIMiddleware(app, config)

Flask

from flask import Flask
from klyna import KlynaFlask, KlynaConfig

app = Flask(__name__)
config = KlynaConfig(api_key='sk_live_...')
klyna = KlynaFlask(app, config)

Application factory pattern:

from klyna import KlynaFlask, KlynaConfig

klyna = KlynaFlask()

def create_app():
    app = Flask(__name__)
    klyna.init_app(app, KlynaConfig(api_key='sk_live_...'))
    return app

Django

Add to settings.py:

MIDDLEWARE = [
    'klyna.middleware.django.KlynaDjangoMiddleware',
    # ... your other middleware
]

KLYNA_API_KEY = 'sk_live_...'

Or configure programmatically in wsgi.py:

from klyna import KlynaConfig
from klyna.middleware.django import KlynaDjangoMiddleware

application = get_wsgi_application()
application = KlynaDjangoMiddleware(application, KlynaConfig(api_key='sk_live_...'))

Starlette

from starlette.applications import Starlette
from klyna import KlynaASGIMiddleware, KlynaConfig

app = Starlette(routes=[...])
app = KlynaASGIMiddleware(app, KlynaConfig(api_key='sk_live_...'))

Configuration Reference

Option Type Default Description
api_key str required Your Klyna API key (sk_live_...)
base_url str https://app.klyna.io Override for self-hosted deployments
batch_size int 50 Flush when queue reaches this size
flush_interval float 5.0 Flush interval in seconds
sample_rate float 1.0 Fraction of requests to capture (0.0–1.0)
ignored_paths List[str] ['/health', '/healthz', '/readyz', '/metrics', '/favicon.ico'] Paths to skip
timeout float 10.0 HTTP request timeout in seconds
debug bool False Log SDK activity to stderr

Graceful Shutdown

The SDK registers an atexit handler automatically. For explicit control:

import signal
from klyna import KlynaClient, KlynaConfig

client = KlynaClient(KlynaConfig(api_key='sk_live_...'))

def handler(sig, frame):
    client.shutdown()
    raise SystemExit(0)

signal.signal(signal.SIGTERM, handler)

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

klyna-1.0.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

klyna-1.0.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file klyna-1.0.0.tar.gz.

File metadata

  • Download URL: klyna-1.0.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for klyna-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e279e451a3071fa5b470a1e298116a969414fdf7a97b08c9e284b4bc725033df
MD5 7c1e5f6f234113290e7607b1819a3f27
BLAKE2b-256 a38b56ea5cdd2a29b71ecfddd0dd401b1bb24a13f2c97ee1d5486579a93c2e42

See more details on using hashes here.

File details

Details for the file klyna-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: klyna-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for klyna-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 756b6e2097674c74f61264d8615695b9b57a27e63857476eaa3a252a093e4829
MD5 8f022e6138c74443c4dc8bd0893efa82
BLAKE2b-256 d7e5b5d651acf5b99780e1ebae6581230cb1f75e9044578b98ce0590215eedf4

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