Skip to main content

flagrant-client-python

A Python client for fetching feature flags from a Flagrant server, with pluggable transports, optional caching, and stale-on-error fallback.

Transports

FlagrantClient doesn't talk to the network itself - it delegates to a Transport, a small protocol with a single fetch(project, environment, identity) -> list[Feature] method (plus close()). This keeps the client's caching/fallback logic independent of how features are actually retrieved, and makes it easy to add new transports or swap them in tests.

Two transports ship today:

  • HttpTransport - calls the endpoint GET /api/v1/projects/{project}/envs/{environment}/features over HTTP via httpx, sending the identity as an X-Flagrant-Identity header.
  • GrpcTransport - calls for the features over gRPC, sending the identity as an x-flagrant-identity metadata entry. Accepts any grpc-core target string, including unix: sockets.

Both transports retry on transient failures with exponential backoff (retries, backoff_factor), and both classify errors into one of two exceptions defined in transport.py:

  • TransientError - the fetch failed in a way that might be resolved by falling back to a stale cache entry or a default handler (e.g. server errors, UNAVAILABLE/UNKNOWN/INTERNAL/RESOURCE_EXHAUSTED gRPC codes, connection errors).
  • PermanentError - the failure should propagate to the caller immediately (e.g. 4xx responses, malformed feature payloads).

This split lets FlagrantClient.get_features react differently depending on whether a retry-worthy or a nonrecoverable failure occurred, regardless of which transport raised it.

Caching and fallback

FlagrantClient optionally wraps fetches in an LRUCache (per (environment, identity) key), configured via FlagsmithOpts(cache_size=..., cache_ttl=...). On a TransientError, the client tries a stale cache entry before falling back to a user-supplied default_handler, and only re-raises if neither is available.

Testing in IPython

With the dev dependencies installed and a Flagrant gRPC server listening on a Unix socket at /tmp/flagrant/grpc.sock:

uv run ipython
import flagrant.client as c
import flagrant.grpc_transport as gt

t = gt.GrpcTransport("unix:/tmp/flagrant/grpc.sock")
client = c.FlagrantClient(project="demo", transport=t)
client.get_features(environment="prod", identity="foo")

Swap in flagrant.http_transport.HttpTransport("http://localhost:3030") to hit an HTTP server instead - the rest of the snippet stays the same, since FlagrantClient only depends on the Transport protocol.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flagrant_client-0.1.0.tar.gz (146.0 kB view details)

Uploaded Source

Built Distribution

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

flagrant_client-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flagrant_client-0.1.0.tar.gz
  • Upload date:
  • Size: 146.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","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 flagrant_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10cf758faba9d0fc1442579981cb8971f991dc0ad247e41b49cf59852b0783bc
MD5 e41784fe4a0c3b305dc087bc96047232
BLAKE2b-256 d9d33b8b762d989745c026e381dad3ee359624eafc0b7ce0bf6566d3d99e7d56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flagrant_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","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 flagrant_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6195086e8877b3c1c6790c196657c33f70180276b23e565ba958bd449604128e
MD5 9d4850e70b82b800fd998491402cc1f1
BLAKE2b-256 48d934b0ea64f906ba5b4dd90f9a5eb79c85a14a3935262bc59e8653c153852a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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