Skip to main content

Luniq.AI server-side SDK for Python — track + identify + feature flags from your backend.

Project description

luniq

Server-side SDK for Luniq.AI. Track events, identify users, and evaluate feature flags from any Python backend.

Install

pip install luniq

Usage

import os
from luniq import Luniq

luniq = Luniq(
    api_key=os.environ["LUNIQ_API_KEY"],
    endpoint="https://your-luniq-host.com",  # optional; defaults to https://uselunaai.com
    environment="PRD",
)

# Track from a backend route (Flask example)
@app.post("/api/orders")
def create_order():
    order = db.orders.create(request.json)
    luniq.track(
        "order_placed",
        visitor_id=g.user.visitor_id,
        account_id=g.user.id,
        properties={"amount": order.total, "sku_count": len(order.items)},
    )
    return order

# Server-side feature flag evaluation
@app.get("/api/checkout")
def checkout():
    flags = luniq.flags(visitor_id=g.user.visitor_id, traits={"plan": g.user.plan})
    if flags.get("new_checkout_v2"):
        return redirect("/checkout/v2")
    return redirect("/checkout/v1")

# On graceful shutdown
import atexit
atexit.register(luniq.shutdown)

API

Luniq(api_key, endpoint=..., **opts)

  • api_key (required) — workspace API key with write or admin scope
  • endpoint — base URL of your Luniq deployment (default https://uselunaai.com)
  • environmentPRD / STG / DEV (default PRD)
  • flush_interval_ms — default 10000
  • max_queue_size — default 10000
  • redact_pii — default True; auto-redacts emails, phones, cards, SSNs
  • session — optional requests.Session for connection reuse / testing

track(name, visitor_id, account_id=None, properties=None, timestamp=None)

Buffers an event for batched async upload. Non-blocking.

identify(visitor_id, account_id=None, traits=None)

Emits a $identify event with the supplied trait set.

flags(visitor_id, account_id=None, traits=None) -> dict

Fetches the current flag evaluation from Luniq for this visitor and caches the result for sync access via flag(). Returns {} on network or server error.

flag(visitor_id, key) -> Any

Sync — returns the cached flag value. Call flags() once first to populate the cache. Returns False if the visitor or key isn't cached.

flush()

Force-drain the buffered queue. Auto-called by a daemon background thread every flush_interval_ms. Safe to call manually before process exit.

shutdown()

Stops the background flush thread and flushes one last time. Call this before the process exits to avoid losing buffered events.

License

Apache-2.0.

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

luniq-1.0.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

luniq-1.0.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for luniq-1.0.0.tar.gz
Algorithm Hash digest
SHA256 75895045c4bd2d9e4c6640fba146d0ceb5febed8b9311a4b849ea35bee3c0d08
MD5 896711cfe17eee1e3eb47a750f1ae568
BLAKE2b-256 15ac7a76e3faa547830ef4619d297bf63f11ae5dcabcde58546438ed6735cf5f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for luniq-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dae52eab79672c4080255769ed851b33105ac73e108de5ea273760af485730ee
MD5 0d8270b55ed7c81db98828372bfa11d7
BLAKE2b-256 44b40a5552c77d3897259bb3c24bee16b7c181bb142936f7cd89fee2e5bd6d2a

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