Skip to main content

Flaggle

PyPI - Version PyPI Downloads GitHub Actions Workflow Status PyPI - Python Version

Overview

Flaggle is a robust and flexible Python library for managing feature flags in your applications. Feature flags (also known as feature toggles) are a software development technique that allows you to enable or disable features dynamically, perform gradual rollouts, and control feature availability without redeploying your code. Designed for simplicity and extensibility, Flaggle supports a variety of flag types and operations, making it easy to adapt to any project or workflow.

Whether you're building a small script or a large-scale production system, Flaggle helps you ship faster, experiment safely, and deliver value to your users with confidence.


Table of Contents


Features

  • Simple API for defining and evaluating feature flags
  • Supports boolean, string, numeric, array, and null flag types
  • Rich set of comparison operations (EQ, NE, GT, LT, IN, etc.)
  • JSON-based flag configuration
  • Easy integration with any Python application
  • Thread-safe and production-ready

Installation

Install from PyPI:

pip install python-flaggle

Or with Poetry:

poetry add python-flaggle

Getting Started

The easiest way to use Flaggle is to create a Flaggle instance that fetches feature flags from a remote JSON endpoint. This is the recommended and most common usage pattern.

from python_flaggle import Flaggle

# Create a Flaggle instance that fetches flags from a remote endpoint
flaggle = Flaggle(url="https://api.example.com/flags", interval=60)

# Access a flag by name and check if it is enabled
if flaggle.flags["feature_a"].is_enabled():
    print("Feature A is enabled!")

# Use a flag with a value and operation
if flaggle.flags["min_version"].is_enabled(4):
    print("Version is supported!")

# Check a string flag
if flaggle.flags["env"].is_enabled("production"):
    print("Production environment!")

Flaggle Class: Configuration & Usage

The Flaggle class is the main entry point for using feature flags in your application. It is designed to periodically fetch flag definitions from a remote JSON endpoint and provide a simple API for evaluating those flags at runtime.

Initialization

from python_flaggle import Flaggle

flaggle = Flaggle(
    url="https://api.example.com/flags",   # Endpoint returning flag JSON
    interval=60,                            # Polling interval in seconds (default: 60)
    default_flags=None,                     # Optional: fallback flags if fetch fails
    timeout=10,                             # HTTP timeout in seconds (default: 10)
    verify_ssl=True                         # Verify SSL certificates (default: True)
)

Parameters

Parameter Type Description
url str The HTTP(S) endpoint to fetch the flags JSON from
interval int How often (in seconds) to poll for flag updates
default_flags dict (Optional) Fallback flags if remote fetch fails
timeout int (Optional) HTTP request timeout in seconds (default: 10)
verify_ssl bool (Optional) Whether to verify SSL certificates (default: True)

Properties

  • flags: A dictionary of flag name to Flag object, always up-to-date with the latest fetched values.
  • last_update: The last time the flags were updated.
  • url, interval, timeout, verify_ssl: The configuration values used.

Example Usage

# Check if a feature is enabled
if flaggle.flags["feature_a"].is_enabled():
    ...

# Evaluate a flag with a custom value (e.g., for numeric or string flags)
if flaggle.flags["min_version"].is_enabled(5):
    ...

Supported Operations

Flaggle supports a variety of operations for evaluating feature flags. These operations can be used to control feature availability based on different types of values. Below are the supported operations, their descriptions, and usage examples:

Operation Description Example Usage
EQ Equal to FlagOperation.EQ(5, 5) → True
NE Not equal to FlagOperation.NE("a", "b") → True
GT Greater than FlagOperation.GT(10, 5) → True
GE Greater than or equal to FlagOperation.GE(5, 5) → True
LT Less than FlagOperation.LT(3, 5) → True
LE Less than or equal to FlagOperation.LE(3, 3) → True
IN Value is in a list/array FlagOperation.IN("BR", ["BR", "US"]) → True
NI Value is not in a list/array FlagOperation.NI("FR", ["BR", "US"]) → True

Advanced Usage: The Flag Class

For advanced scenarios, you can create and evaluate Flag objects directly, or load them from a JSON structure. This is useful for testing, custom flag sources, or when you want to bypass remote fetching.

Manual Flag Creation

from python_flaggle import Flag, FlagOperation

flag = Flag(name="feature_x", value=True)
if flag.is_enabled():
    print("Feature X is enabled!")

flag = Flag(name="min_version", value=2, operation=FlagOperation.GE)
if flag.is_enabled(3):
    print("Version is supported!")

Loading Flags from JSON

from python_flaggle import Flag

json_data = {
    "flags": [
        {"name": "feature_x", "value": 42, "operation": "eq"},
        {"name": "env", "value": "prod", "operation": "ne"},
        {"name": "region", "value": ["US", "BR"], "operation": "in"}
    ]
}
flags = Flag.from_json(json_data)

JSON Schema for Flags Endpoint

The endpoint provided to Flaggle must return a JSON object with a top-level flags key, which is a list of flag definitions. Each flag definition should have the following structure:

{
  "flags": [
    {
      "name": "feature_a",                // (string, required) Unique flag name
      "description": "Enable feature A",   // (string, optional) Human-readable description
      "value": true,                        // (any, required) The flag value (bool, str, int, float, list, or null)
      "operation": "eq"                    // (string, optional) Operation for evaluation (see below)
    },
    ...
  ]
}

Supported Operations

  • eq, ne, gt, ge, lt, le, in, ni
  • If operation is omitted, the flag is evaluated as a simple boolean/truthy value.

Example JSON

{
  "flags": [
    {"name": "feature_a", "value": true},
    {"name": "min_version", "value": 3, "operation": "ge"},
    {"name": "region", "value": ["US", "BR"], "operation": "in"}
  ]
}

Contributing

Contributions are welcome! Please open issues or submit pull requests for bug fixes, new features, or improvements. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.


TODO / Roadmap

  • Customizable API Call Logic: Allow users to provide their own HTTP client or customize how flags are fetched, instead of always using requests.get.
  • Pluggable Storage Backends: Support for loading flags from sources other than HTTP endpoints (e.g., local files, databases, environment variables).
  • Flag Change Listeners: Add hooks or callbacks to notify the application when a flag value changes.
  • Admin/Management UI: Provide a web interface for managing and toggling flags in real time.
  • Advanced Rollout Strategies: Support for percentage rollouts, user targeting, and A/B testing.
  • Async Support: Add async/await support for non-blocking flag fetching and updates.
  • Type Annotations & Validation: Improve type safety and validation for flag values and operations.
  • Better Error Handling & Logging: More granular error reporting and logging options.
  • Extensive Documentation & Examples: Expand documentation with more real-world usage patterns and advanced scenarios.

Contributions and suggestions are welcome! Please open an issue or pull request if you have ideas for improvements.

Metadata

Release files for python-flaggle 0.3.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 python-flaggle 0.3.1
File Size Uploaded
python_flaggle-0.3.1.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-flaggle 0.3.1
File Interpreter ABI Platform
python_flaggle-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / python_flaggle-0.3.1.tar.gz

Download URL python_flaggle-0.3.1.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
83c83578b47486577b604565940264dcd11941131951154703fb43dc31edc187
BLAKE2b-256 checksum
How to use checksums
a577a690c24af07e71285556952d13bf418240b85b24052d8d2f64697350aa71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2025.

Transparency log

Release files / python_flaggle-0.3.1-py3-none-any.whl

Download URL python_flaggle-0.3.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c204d0009b293da8f8aec1efd826767d20f143ea66b4d5dccf1eb784c852694e
BLAKE2b-256 checksum
How to use checksums
43f6aef2b480cabe6d3270a52b7bfb27e1b9a6ae9cef4d2e3f13ce6c35148183
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

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