Skip to main content

Flipt Client Python

flipt-client-python

The flipt-client-python library contains the Python source code for the Flipt client-side evaluation client.

Installation

pip install flipt-client

How Does It Work?

The flipt-client-python library is a wrapper around the flipt-engine-ffi library.

All evaluation happens within the SDK, using the shared library built from the flipt-engine-ffi library.

Because the evaluation happens within the SDK, the SDKs can be used in environments where the Flipt server is not available or reachable after the initial data is fetched.

Data Fetching

Upon instantiation, the flipt-client-python library will fetch the flag state from the Flipt server and store it in memory. This means that the first time you use the SDK, it will make a request to the Flipt server.

Polling (Default)

By default, the SDK will poll the Flipt server for new flag state at a regular interval. This interval can be configured using the update_interval option when constructing a client. The default interval is 120 seconds.

Streaming (Flipt Cloud/Flipt v2)

Flipt Cloud and Flipt v2 users can use the streaming fetch method to stream flag state changes from the Flipt server to the SDK.

When in streaming mode, the SDK will connect to the Flipt server and open a persistent connection that will remain open until the client is closed. The SDK will then receive flag state changes in real-time.

Retries

The SDK will automatically retry fetching (or initiating streaming) flag state if the client is unable to reach the Flipt server temporarily.

The SDK will retry up to 3 times with an exponential backoff interval between retries. The base delay is 1 second and the maximum delay is 30 seconds.

Retriable errors include:

  • 429 Too Many Requests
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout
  • Other potential transient network or DNS errors

Supported Architectures

This SDK currently supports the following OSes/architectures:

  • Linux x86_64
  • Linux arm64
  • MacOS x86_64
  • MacOS arm64
  • Windows x86_64

Migration Notes

Pre-1.0.0 -> 1.0.0

This section is for users who are migrating from a previous (pre-1.0.0) version of the SDK.

  • FliptEvaluationClient has been renamed to FliptClient.
  • The namespace argument is now part of ClientOptions as namespace (and optionally environment).
  • update_interval and request_timeout are now timedelta objects instead of int.
  • All response models are now Pydantic models with explicit types and improved docstrings.
  • Backwards compatibility with Pydantic v1 is now maintained.
  • All errors now inherit from FliptError and use specific subclasses like ValidationError and EvaluationError.
  • The client and models now follow Python naming conventions (snake_case for methods and fields).
  • The minimum supported Python version is now 3.11.

Usage

from flipt_client import FliptClient
from flipt_client.models import ClientOptions, ClientTokenAuthentication

client = FliptClient(
    opts=ClientOptions(
        url="http://localhost:8080",
        authentication=ClientTokenAuthentication(client_token="your-token"),
    )
)

variant_result = client.evaluate_variant(flag_key="flag1", entity_id="entity", context={"fizz": "buzz"})
print(variant_result)

# Important: always close the client to release resources
client.close()

Constructor Arguments

The FliptClient constructor accepts a single opts argument:

  • opts: An instance of the ClientOptions class. The structure is:
    • environment: The environment (Flipt v2) to fetch flag state from. If not provided, the client will default to the default environment.
    • namespace: The namespace to fetch flag state from. If not provided, the client will default to the default namespace.
    • url: The URL of the upstream Flipt instance. Defaults to http://localhost:8080.
    • request_timeout: Timeout for requests. Defaults to no timeout.
    • update_interval: Interval to fetch new flag state. Defaults to 120s.
    • authentication: Authentication strategy. See Authentication.
    • reference: The namespace or reference key. Defaults to default.
    • fetch_mode: Fetch mode (polling or streaming). Defaults to polling.
    • error_strategy: Error strategy (fail or fallback). Defaults to fail.
    • snapshot: A base64 encoded snapshot of the engine state. Defaults to None. See Snapshotting.
    • tls_config: TLS configuration for connecting to Flipt servers with custom certificates. See TLS Configuration.

Authentication

The FliptClient supports:

TLS Configuration

The FliptClient supports TLS configuration for connecting to Flipt servers with custom certificates, self-signed certificates, or mutual TLS authentication.

The tls_config option accepts a TlsConfig object with the following options:

  • ca_cert_file: Path to custom CA certificate file (PEM format). Use this to trust self-signed certificates or custom certificate authorities.
  • ca_cert_data: Raw CA certificate content (PEM format). Alternative to ca_cert_file for providing certificate data directly.
  • insecure_skip_verify: Skip certificate verification (development only). Set to True to disable TLS certificate and hostname verification. Warning: Only use this for development/testing.
  • insecure_skip_hostname_verify: Skip hostname verification while maintaining certificate validation (development only). Set to True to disable hostname verification but still validate the certificate chain. Warning: Only use this for development/testing.
  • client_cert_file: Client certificate file for mutual TLS (PEM format). Required for mTLS authentication.
  • client_key_file: Client key file for mutual TLS (PEM format). Required for mTLS authentication.
  • client_cert_data: Raw client certificate content (PEM format). Alternative to client_cert_file.
  • client_key_data: Raw client key content (PEM format). Alternative to client_key_file.

Note: Data fields (*_data) take precedence over file paths (*_file) when both are provided.

Examples

Self-signed certificate with custom CA:

from flipt_client import FliptClient
from flipt_client.models import ClientOptions, TlsConfig

# Using CA certificate file
tls_config = TlsConfig(
    ca_cert_file="/path/to/ca.crt"
)

client = FliptClient(
    opts=ClientOptions(
        url="https://flipt.example.com:8443",
        tls_config=tls_config
    )
)

Skip certificate verification (development only):

tls_config = TlsConfig(
    insecure_skip_verify=True
)

client = FliptClient(
    opts=ClientOptions(
        url="https://localhost:8443",
        tls_config=tls_config
    )
)

Self-signed certificate with hostname mismatch:

# For self-signed certificates with hostname mismatch
tls_config = TlsConfig(
    ca_cert_file="/path/to/ca.crt",
    insecure_skip_hostname_verify=True
)

client = FliptClient(
    opts=ClientOptions(
        url="https://localhost:8443",
        tls_config=tls_config
    )
)

Mutual TLS authentication:

tls_config = TlsConfig(
    ca_cert_file="/path/to/ca.crt",
    client_cert_file="/path/to/client.crt",
    client_key_file="/path/to/client.key"
)

client = FliptClient(
    opts=ClientOptions(
        url="https://flipt.example.com:8443",
        tls_config=tls_config
    )
)

Using certificate data instead of files:

# Read certificate contents
with open("/path/to/ca.crt", "r") as f:
    ca_cert_data = f.read()

tls_config = TlsConfig(
    ca_cert_data=ca_cert_data
)

client = FliptClient(
    opts=ClientOptions(
        url="https://flipt.example.com:8443",
        tls_config=tls_config
    )
)

Error Handling

All errors raised by the client derive from flipt_client.errors.FliptError:

  • ValidationError: Raised for invalid arguments or configuration.
  • EvaluationError: Raised for evaluation failures (e.g., flag not found).

Example:

from flipt_client.errors import ValidationError, EvaluationError

try:
    client.evaluate_variant(flag_key=None, entity_id="entity")
except ValidationError as e:
    print(f"Validation error: {e}")
except EvaluationError as e:
    print(f"Evaluation error: {e}")

Snapshotting

The client supports snapshotting of flag state as well as seeding the client with a snapshot for evaluation. This is helpful if you want to use the client in an environment where the Flipt server is not guaranteed to be available or reachable on startup.

To get the snapshot for the client, you can use the get_snapshot method. This returns a base64 encoded JSON string that represents the flag state for the client.

You can set the snapshot for the client using the snapshot option when constructing a client.

Note: You most likely will want to also set the error_strategy to fallback when using snapshots. This will ensure that you wont get an error if the Flipt server is not available or reachable even on the initial fetch.

You also may want to store the snapshot in a local file so that you can use it to seed the client on startup.

[!IMPORTANT] If the Flipt server becomes reachable after the setting the snapshot, the client will replace the snapshot with the new flag state from the Flipt server.

Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request.

License

This project is licensed under the MIT License.

Metadata

Release files for flipt-client 1.4.4

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

Source distribution (sdist)

Source distribution for flipt-client 1.4.4
File Size Uploaded
flipt_client-1.4.4.tar.gz 24.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for flipt-client 1.4.4
File Interpreter ABI Platform
flipt_client-1.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 48.5 MB

Release files / flipt_client-1.4.4.tar.gz

Download URL flipt_client-1.4.4.tar.gz
Size 24.2 MB
Tags Source
SHA-256 checksum
How to use checksums
6b90f98cb60dc275313436ca15148f7348a6d08b86beb0879f37d91458575785
BLAKE2b-256 checksum
How to use checksums
b9ec746f7d1ab0bf1b693dfc0bd8f596a35406c5815a05992cf56e2d2ef41a7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.11.16 Linux/6.17.0-1022-azure

Release files / flipt_client-1.4.4-py3-none-any.whl

Download URL flipt_client-1.4.4-py3-none-any.whl
Size 24.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b504f028d7e7d2ca8e8e259853bec715df61d1c585c23f394f074e5e0002f842
BLAKE2b-256 checksum
How to use checksums
53039e859154f5dbc95d69959e395fd272c2c01b2d100838012b9d6b5e78fd0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.11.16 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

This release

1.4.4 This release

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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