Metadata-Version: 2.4
Name: flagcel-openfeature
Version: 0.1.0
Summary: OpenFeature provider for Flagcel with local CEL evaluation
Author: picunada
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/picunada/flagcel/tree/main/sdks/python#readme
Project-URL: Repository, https://github.com/picunada/flagcel
Project-URL: Issues, https://github.com/picunada/flagcel/issues
Keywords: flagcel,openfeature,feature-flags,feature-toggles,cel
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: cel-expr-python<0.2,>=0.1.2
Requires-Dist: openfeature-sdk<1,>=0.9
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"

# Flagcel OpenFeature Provider for Python

OpenFeature provider for Flagcel with local CEL evaluation. The provider polls
Flagcel for evaluation definitions, compiles rules with `cel-expr-python`, and
evaluates flags in-process.

```sh
python -m pip install flagcel-openfeature
```

```python
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from flagcel_openfeature import FlagcelProvider

provider = FlagcelProvider(
    endpoint="http://localhost:8080/api/v1",
    api_key="fc_example_secret",
)
api.set_provider(provider)

client = api.get_client("checkout-service")
enabled = client.get_boolean_value(
    "new-checkout",
    False,
    EvaluationContext(
        targeting_key="u_123",
        attributes={"user": {"id": "u_123", "country": "US"}},
    ),
)
```

## Behavior

- Requires Python 3.11+.
- Fetches `GET /eval/definitions` relative to the configured endpoint.
- Sends `Authorization: Bearer <api_key>` when an API key is configured; the API key selects the evaluation environment.
- Polls definitions every 30 seconds by default.
- Uses `ETag` and `If-None-Match` to avoid reloading unchanged definitions.
- Evaluates flags locally with CEL expressions from the latest definitions.
- Returns OpenFeature defaults with provider-not-ready details if no definitions have loaded.
- Keeps using last-known definitions after later refresh failures.
- Maps Flagcel reason, variant, and value type into OpenFeature resolution details.

Configure the polling interval in seconds:

```python
provider = FlagcelProvider(
    endpoint="http://localhost:8080/api/v1",
    api_key="fc_example_secret",
    poll_interval=10.0,
)
```
