Skip to main content

Python SDK for FOFF Feature Config service

Project description

FOFF Feature Config Python SDK

Python SDK for the FOFF Feature Config service. Provides both sync and async clients with built-in caching and background polling.

Installation

pip install foff

Quick Start

Sync Client

from foff import Client, Config

config = Config(
    api_key="your-api-key",
    base_url="https://foff.twospoon.ai/live",
    scope="production",
    polling_interval=30,  # refresh configs every 30 seconds (0 to disable)
)

with Client(config) as client:
    value = client.get_feature_config("dark_mode", ["prod", "us-east", "acme"])
    print(value)  # e.g. {"enabled": True, "beta": True}

Async Client

import asyncio
from foff import AsyncClient, Config

config = Config(
    api_key="your-api-key",
    base_url="https://foff.twospoon.ai/live",
    scope="production",
    polling_interval=30,
)

async def main():
    async with AsyncClient(config) as client:
        value = client.get_feature_config("dark_mode", ["prod", "us-east", "acme"])
        print(value)

asyncio.run(main())

Configuration

Parameter Type Required Default Description
api_key str Yes API key for authentication
base_url str Yes Base URL of the FOFF service
scope str Yes Scope identifier for your configs
polling_interval int No 30 Polling interval in seconds (0 disables polling)

Feature Lookup

value = client.get_feature_config(feature_name, ordered_hierarchy)
  • feature_name — the name of the feature flag
  • ordered_hierarchy — a list of hierarchy levels from broadest to most specific

The SDK resolves configs from most specific to least specific. Given ["prod", "us-east", "acme"], it checks:

  1. prod#us-east#acme
  2. prod#us-east
  3. prod
  4. default

Returns the first match, or None if the feature doesn't exist.

Client Lifecycle

Sync

The Client constructor performs a blocking initial fetch. If the fetch fails, an exception is raised and no resources are leaked.

# Context manager (recommended)
with Client(config) as client:
    ...

# Manual
client = Client(config)
try:
    ...
finally:
    client.close()

Async

The AsyncClient constructor is lightweight — no network calls. Call start() or use async with to initialize.

# Context manager (recommended)
async with AsyncClient(config) as client:
    ...

# Manual
client = AsyncClient(config)
await client.start()
try:
    ...
finally:
    await client.close()

Background Polling

When polling_interval > 0, the client refreshes configs in the background. Polling errors are silently ignored — the client continues serving the last successfully fetched configs.

Call close() (or exit the context manager) to stop polling and release resources.

Development

pip install -e ".[dev]"
pytest tests/

Contributing

License

See LICENSE.

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

foff-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

foff-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: foff-0.1.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for foff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0578e5e7d1780100c2e34047b3bdfd6eee240bf987d9be9ea5a370323dff5d4c
MD5 c9c10be935f81885fc12e412106275df
BLAKE2b-256 8c9d7feee14a09f5ae59655b3b925899595545b212e56a99941e0ffa247d7019

See more details on using hashes here.

Provenance

The following attestation bundles were made for foff-0.1.0.tar.gz:

Publisher: release.yml on twospoon/foff-feature-config-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: foff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for foff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd4087973c2c9cb97494f53c4e503d8b40388ce864f153b53c0bfb0630a591d4
MD5 d687d7a3c2c41cfa60a30bb9fca435cc
BLAKE2b-256 21d2422b1485512c782936ed6a47890e4009e92a46b94b7efb546a0971231ee6

See more details on using hashes here.

Provenance

The following attestation bundles were made for foff-0.1.0-py3-none-any.whl:

Publisher: release.yml on twospoon/foff-feature-config-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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