Skip to main content

Tombstone Python SDK — server-side feature flag evaluation with OpenFeature support

Project description

Tombstone Python SDK

The official Python SDK for Tombstone — production intelligence layer for feature flags.

Installation

pip install tombstone

Quick Start

from tombstone import TombstoneClient

client = TombstoneClient(
    api_url="http://localhost:8081",
    sdk_key="sdk-dev-token-change-in-prod",
    environment="development",
)
client.initialize()

enabled = client.is_enabled("my-first-flag", {"user_id": "user-123"})
print(f"Feature enabled: {enabled}")

Configuration

Parameter Type Required Default Description
api_url str Yes Base URL of your Tombstone flag-api service
sdk_key str Yes SDK authentication token (set via FLAG_API_TOKEN in infra/.env)
environment str No "production" Environment name (development, staging, production)
cache_ttl int No 30 Flag cache TTL in seconds
timeout float No 5.0 HTTP request timeout in seconds
stream_url str No None Gateway SSE URL for real-time updates (e.g. http://localhost:8080)
from tombstone import TombstoneClient

client = TombstoneClient(
    api_url="http://localhost:8081",
    sdk_key="sdk-dev-token-change-in-prod",
    environment="staging",
    cache_ttl=60,
    timeout=3.0,
    stream_url="http://localhost:8080",
)
client.initialize()

Usage

is_enabled()

Returns True if the flag is enabled for the given evaluation context.

# Simple boolean flag
enabled = client.is_enabled("my-first-flag", {"user_id": "user-123"})

# With richer context for targeting rules
enabled = client.is_enabled("checkout-v2", {
    "user_id": "user-123",
    "email": "user@example.com",
    "plan": "pro",
    "country": "US",
})

if enabled:
    show_new_checkout()
else:
    show_legacy_checkout()

get_variation()

Returns the variation value for multivariate flags. Use when you need string/number/JSON values rather than a boolean.

# String variation
theme = client.get_variation("ui-theme", {"user_id": "user-123"}, default="light")
# Returns: "light", "dark", or "high-contrast"

# JSON variation
config = client.get_variation("pricing-config", {"user_id": "user-123"}, default={})
# Returns: {"monthly": 29, "annual": 249}

# Numeric variation
limit = client.get_variation("rate-limit-tier", {"user_id": "user-123"}, default=100)

Async Support

The SDK ships an async client for use with asyncio, FastAPI, and other async frameworks.

import asyncio
from tombstone import AsyncTombstoneClient

async def main():
    client = AsyncTombstoneClient(
        api_url="http://localhost:8081",
        sdk_key="sdk-dev-token-change-in-prod",
        environment="development",
    )
    await client.initialize()

    enabled = await client.is_enabled("my-first-flag", {"user_id": "user-123"})
    print(f"Feature enabled: {enabled}")

    await client.close()

asyncio.run(main())

FastAPI integration

from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from tombstone import AsyncTombstoneClient

client: AsyncTombstoneClient

@asynccontextmanager
async def lifespan(app: FastAPI):
    global client
    client = AsyncTombstoneClient(
        api_url="http://localhost:8081",
        sdk_key="sdk-dev-token-change-in-prod",
        environment="production",
    )
    await client.initialize()
    yield
    await client.close()

app = FastAPI(lifespan=lifespan)

@app.get("/checkout")
async def checkout(request: Request, user_id: str):
    enabled = await client.is_enabled("checkout-v2", {"user_id": user_id})
    return {"checkout_version": "v2" if enabled else "v1"}

Local Development

Start the full Tombstone stack first:

git clone https://github.com/sairam0424/Tombstone.git
cd Tombstone
cp infra/.env.example infra/.env
make dev

The flag-api will be available at http://localhost:8081. The default SDK token is sdk-dev-token-change-in-prod (set via FLAG_API_TOKEN in infra/.env).

# Local development client — no changes needed
client = TombstoneClient(
    api_url="http://localhost:8081",
    sdk_key="sdk-dev-token-change-in-prod",
    environment="development",
)

Testing

Use TombstoneTestClient for unit tests — it evaluates flags locally without any network calls.

from tombstone.testing import TombstoneTestClient

def test_checkout_page():
    client = TombstoneTestClient()
    client.set_flag("checkout-v2", enabled=True)
    client.set_variation("ui-theme", "dark")

    # Your application code under test
    result = render_checkout(client)

    assert result["checkout_version"] == "v2"
    assert result["theme"] == "dark"

def test_checkout_page_disabled():
    client = TombstoneTestClient()
    client.set_flag("checkout-v2", enabled=False)

    result = render_checkout(client)

    assert result["checkout_version"] == "v1"

TombstoneTestClient implements the same interface as TombstoneClient, so you can inject it via dependency injection or monkeypatching.

Requirements

  • Python 3.10+
  • httpx (HTTP client)
  • pydantic v2 (config validation)

No other runtime dependencies.

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

tombstone_sdk-0.2.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

tombstone_sdk-0.2.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file tombstone_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: tombstone_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tombstone_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 20f93a15dcac8c4afcaa2e066262e82cb10cd7dd967d297b681775225175f80d
MD5 9c8e8ad0d434dfa69e078b2e917bd8bf
BLAKE2b-256 e5df9c0c4d28ad65512229779bd4f240659df24ed08ea84127d9bc928b0655e9

See more details on using hashes here.

File details

Details for the file tombstone_sdk-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for tombstone_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea436c7d5f4309c3c5f2494203755bad165a6378e7c8f38e550d5ac06edef627
MD5 9a35229edf4c49a2e8600f14feb011c8
BLAKE2b-256 4c6e204804e8dade6bca6133be4703f1d25f10fe813b4faf0199ca658d4753ce

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