Metadata-Version: 2.5
Name: railflag-openfeature
Version: 0.2.1
Summary: Railflag OpenFeature provider for Python: local evaluation, streaming updates
License-Expression: Apache-2.0
Keywords: feature-flags,openfeature,railflag
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: openfeature-sdk>=0.10
Description-Content-Type: text/markdown

# railflag-openfeature

Railflag's OpenFeature provider for Python 3.10+. It downloads your environment's flag config once,
evaluates every flag check in process (about 15 µs, no network call), and picks up changes within a
second over Server-Sent Events. If the stream drops it polls every 30 s, and if Railflag can't be
reached it keeps serving the last config it had. The only dependency is `openfeature-sdk`.

```python
import os
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from railflag import RailflagProvider

api.set_provider_and_wait(RailflagProvider(
    sdk_key=os.environ["RAILFLAG_SERVER_KEY"],          # a server key: Environments → keys
    base_url="https://relay.railflag.com",  # required: your Railflag relay
))
client = api.get_client()

if client.get_boolean_value("new-checkout", False, EvaluationContext("user-42", {"plan": "pro", "country": "GR"})):
    ...
```

- `get_boolean_value`, `get_string_value`, `get_integer_value`, `get_float_value` and `get_object_value` work as in any OpenFeature provider. A wrong type or unknown flag returns your default with an error code.
- `datetime` and `date` attributes are compared as instants, so `before`/`after` rules work with them.
- `api.add_handler(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, fn)` tells you when flags change; `details.flags_changed` lists them.
- Server keys can read every rule. Keep them on the server; browsers use the JavaScript SDK with a client key.

## Same answers as every other SDK

`railflag/evaluate.py` is a port of `packages/eval`. The tests run it against
`packages/eval/vectors/eval-vectors.json` (hashes, buckets and thousands of evaluations generated by
the TypeScript evaluator), so a user lands in the same variation whichever SDK evaluates the flag.
Context values follow JavaScript rules: `1` and `True` are different, numbers print as JavaScript
prints them, and strings sort by UTF-16 code units.

Known differences: regexes in `matches` rules run on Python's `re` (with ASCII `\d`/`\w`), and a
date-time without a time zone is read as UTC.

## Development

```sh
uv sync
uv run pytest
SY_EMAIL=... SY_PASSWORD=... uv run python examples/live_check.py   # against production; rotates the Development server key
```
