Skip to main content

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.

Release files for tombstone-sdk 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tombstone-sdk 0.2.1
File Size Uploaded
tombstone_sdk-0.2.1.tar.gz 18.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tombstone-sdk 0.2.1
File Interpreter ABI Platform
tombstone_sdk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / tombstone_sdk-0.2.1.tar.gz

Download URL tombstone_sdk-0.2.1.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7e25b08aa731531911828e126c77d796d6b98f17ac0af96b2564c3e6817ab0ea
BLAKE2b-256 checksum
How to use checksums
424152aec81d385f0db60f27b59d68bead9cfb014eae6ff8bf013e812f5b919a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / tombstone_sdk-0.2.1-py3-none-any.whl

Download URL tombstone_sdk-0.2.1-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff9237275867642532232deca1c5a9387a28ac0b959d64593b9d0826990c102a
BLAKE2b-256 checksum
How to use checksums
be98f39df2c8da1fc6e2b2a520b8e50003e9736a7c3c16cf83265ddf8f2ad4fa
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page