Skip to main content

Fail-open server SDK for Keeps media-native product analytics

Project description

keeps-ai

The server-only Python SDK for Keeps media-native product analytics. Capture is fail-open: validation, buffering, and delivery failures never change application behavior.

pip install keeps-ai
import os
from keeps import Keeps

keeps = Keeps(api_key=os.environ["KEEPS_API_KEY"])
keeps.identify(user_id, {"plan": "pro"})
generation = keeps.generation(
    model="fal-ai/flux-2-pro",
    provider="fal",
    input={"prompt": prompt, "seed": seed, "steps": 28},
    user_id=user_id,
    session_id=session_id,
    source_assets=[source_row_id] if source_row_id else [],
    properties={"feature": "product-ad", "surface": "canvas"},
)
result = generation.complete(
    requested_assets=1,
    assets=[
        {
            "external_id": output_row_id,
            "media_type": "image",
            "url": url,
            "index": 0,
        }
    ],
    cost={"usd": 0.04},
)
keeps.track(
    "downloaded",
    asset=result.asset_ids[0],
    user_id=user_id,
    session_id=session_id,
    properties={"format": "png"},
)

Use generation.fail(reason="Safety policy", code="nsfw", blocked=True) only when the terminal state is useful product context. Generic provider failures may be omitted.

input is exactly what went to the provider. properties are application-known annotations; do not manually label asset content. Every asset needs one stable customer external_id; URLs are optional fetch references and never identity.

User IDs are HMAC-pseudonymized with the workspace API key before leaving the process. Still use a stable internal ID and never pass email, prompts with secrets, direct PII, or media bytes. Use with Keeps(...) as keeps, call keeps.flush(timeout=2.0), or wrap a serverless handler with keeps.with_flush(handler) at a bounded shutdown boundary.

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

keeps_ai-0.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

keeps_ai-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: keeps_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for keeps_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71b89d50834947bdde31a5729705bcc002c5a66f98d88b2c16d4ad4228c6aa76
MD5 0a66e8bd70402d7d758960ff78c51a6b
BLAKE2b-256 5f1ef45b2c705d52ebae71a5f0a10fe9a4c9dcdb9bca77e58c894dfd04009d30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: keeps_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for keeps_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 836d0dea9f3c0183debfb1dd0a1124d6daaa62d0e2785a04f124c7a93edb0496
MD5 6bffafe0521fdfb733a2754166e38f0b
BLAKE2b-256 b6c017bcd8a613855f469cf4fed19abf1643431ed26453e70f5936469792e15d

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