Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions .flake8

This file was deleted.

72 changes: 31 additions & 41 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,39 @@ jobs:

steps:
- uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v7
- name: Install uv and set Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "0.13.9"
python-version: ${{ matrix.python-version }}
# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: uv sync --locked
- name: Check lint and formatting with Ruff
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-mock build
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
python -m pip install --no-deps .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors
python -m flake8 .
uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
- name: Test with pytest
run: |
python -m pytest
run: uv run --no-sync python -m pytest
- name: Audit concurrency, memory, and thread cleanup
if: matrix.python-version == '3.12' || matrix.python-version == '3.14'
run: python scripts/resource_audit.py --evaluations 20000 --workers 8
run: uv run --no-sync python scripts/resource_audit.py --evaluations 20000 --workers 8
- name: Build production distributions
if: matrix.python-version == '3.12' || matrix.python-version == '3.14'
run: python -m build
run: uv build
- name: Verify wheel contains production packages only
if: matrix.python-version == '3.12' || matrix.python-version == '3.14'
run: python -c "import glob, zipfile; names = zipfile.ZipFile(glob.glob('dist/*.whl')[0]).namelist(); assert not any(name.startswith(('tests/', 'featbit_openfeature/')) for name in names)"
run: uv run --no-sync python -c "import glob, zipfile; names = zipfile.ZipFile(glob.glob('dist/*.whl')[0]).namelist(); assert not any(name.startswith(('tests/', 'featbit_openfeature/')) for name in names)"
- name: Install and smoke-test the built wheel
if: matrix.python-version == '3.14'
run: |
python -m venv "$RUNNER_TEMP/featbit-wheel-test"
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install --upgrade pip
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install dist/*.whl
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip check
"$RUNNER_TEMP/featbit-wheel-test/bin/python" scripts/wheel_smoke.py \
wheel_env="$RUNNER_TEMP/featbit-wheel-test"
uv venv "$wheel_env"
uv pip install --python "$wheel_env/bin/python" dist/*.whl
uv pip check --python "$wheel_env/bin/python"
version="$(uv version --short)"
"$wheel_env/bin/python" scripts/wheel_smoke.py \
--bootstrap tests/fbclient_test_data.json \
--expected-version-file release/package.json
--expected-version "$version"

windows:
runs-on: windows-latest
Expand All @@ -65,39 +59,35 @@ jobs:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v7
- name: Install uv and set Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "0.13.9"
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-mock
python -m pip install -r requirements.txt
python -m pip install --no-deps .
run: uv sync --locked
- name: Test with pytest
run: python -m pytest
run: uv run --no-sync python -m pytest

minimum-dependencies:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- name: Set up Python 3.14
uses: actions/setup-python@v7
- name: Install uv and set Python 3.14
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "0.13.9"
python-version: "3.14"
- name: Install exact minimum dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-mock
python -m pip install \
uv sync --locked
uv pip install \
certifi==2018.4.16 \
urllib3==1.26.5 \
python-dateutil==2.8.2 \
websocket-client==1.0.0
python -m pip install --no-deps .
python -m pip check
uv pip check
- name: Test with pytest
run: python -m pytest
run: uv run --no-sync python -m pytest
- name: Audit concurrency, memory, and thread cleanup
run: python scripts/resource_audit.py --evaluations 20000 --workers 8
run: uv run --no-sync python scripts/resource_audit.py --evaluations 20000 --workers 8
88 changes: 51 additions & 37 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Upload Python Package

on:
Expand All @@ -16,54 +7,77 @@ on:
- main

jobs:
deploy:
build:
name: Build and verify distributions
permissions:
contents: write
contents: read
runs-on: ubuntu-24.04
environment: py-production
outputs:
version: ${{ steps.version.outputs.value }}
steps:
- uses: actions/checkout@v7
- name: Install uv and set Python 3.14
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "0.13.9"
python-version: "3.14"
- name: Read current version
id: version
run: |
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
with open("release/package.json") as file:
print("value=%s" % json.load(file)["version"])
PY
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.14'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build twine
version="$(uv version --short)"
printf 'value=%s\n' "$version" >> "$GITHUB_OUTPUT"
- name: Build package
run: python -m build
run: uv build
- name: Check package metadata
run: python -m twine check dist/*
run: uv run --locked --only-group release twine check dist/*
- name: Install and smoke-test the built wheel
env:
VERSION: ${{ steps.version.outputs.value }}
run: |
python -m venv "$RUNNER_TEMP/featbit-wheel-test"
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install --upgrade pip
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install dist/*.whl
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip check
"$RUNNER_TEMP/featbit-wheel-test/bin/python" scripts/wheel_smoke.py \
wheel_env="$RUNNER_TEMP/featbit-wheel-test"
uv venv "$wheel_env"
uv pip install --python "$wheel_env/bin/python" dist/*.whl
uv pip check --python "$wheel_env/bin/python"
"$wheel_env/bin/python" scripts/wheel_smoke.py \
--bootstrap tests/fbclient_test_data.json \
--expected-version "$VERSION"
- name: Upload verified distributions
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python-distributions
path: |
dist/*.whl
dist/*.tar.gz
if-no-files-found: error

deploy:
name: Publish to PyPI
needs: build
permissions:
contents: write
runs-on: ubuntu-24.04
# GitHub enforces Required reviewers on the py-production environment.
environment: py-production
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: "0.13.9"
- name: Download verified distributions
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: python-distributions
path: dist
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.value }}
VERSION: ${{ needs.build.outputs.version }}
run: |
gh release create "v$VERSION" \
--title "v$VERSION" \
--notes-file release/description.md
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@v1.12.4
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_PASSWORD }}
run: uv publish
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ dmypy.json

### IDEs

#### Zed

/.zed/debug.json

#### VSCode

.vscode/*
Expand Down Expand Up @@ -220,4 +224,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

intergration_tests/*
intergration_tests/*
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
minimum_pre_commit_version: "4.4.0"
default_stages: [pre-commit]

repos:
- repo: local
hooks:
- id: ruff-check
name: Ruff lint
entry: uv run --locked ruff check .
language: unsupported
always_run: true
pass_filenames: false
- id: ruff-format
name: Ruff format
entry: uv run --locked ruff format .
language: unsupported
always_run: true
pass_filenames: false
- id: pytest
name: Run all tests
entry: uv run --locked python -m pytest
language: unsupported
always_run: true
pass_filenames: false
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
## Get Started

### Installation
Install the SDK using pip. This version is compatible with Python 3.10 through 3.14.
This version of the SDK is compatible with Python 3.10 through 3.14.
CI is configured to test compatibility on Linux and Windows through Python 3.14,
including the full unit suite and SDK resource-lifecycle audit.
Free-threaded CPython 3.14 builds are not currently tested or supported.

In a uv project, add the SDK with:

```shell
uv add fb-python-sdk
```

To install the published SDK with pip:

```shell
pip install fb-python-sdk
```
Expand Down Expand Up @@ -83,15 +91,15 @@ shutdown, public runtime exception isolation, and redundant code. Run the
local resource audit with:

```shell
python scripts/resource_audit.py --evaluations 80000 --workers 8
uv run python scripts/resource_audit.py --evaluations 80000 --workers 8
```

To verify WebSocket synchronization, remote evaluation, status changes, event
delivery, and clean shutdown against FeatBit Cloud or a self-hosted evaluation
service, set `FEATBIT_ENV_SECRET` and run:

```shell
python scripts/live_integration_check.py
uv run python scripts/live_integration_check.py
```

The live script never prints or persists the environment secret. See the
Expand Down Expand Up @@ -274,6 +282,33 @@ client.track_metric(user, event_name, numeric_value);
Make sure `track_metric` is called after the related feature flag is evaluated by simply calling `variation` or `variation_detail`
otherwise, the custom event may not be included into the experiment result.

## Development

From the repository root, use [uv](https://docs.astral.sh/uv/getting-started/installation/)
to sync the locked dependencies and run the project checks:

```shell
uv sync --locked
uv run ruff check .
uv run ruff format --check .
uv run python -m pytest
uv build
```

Apply lint fixes and format the Python files with
`uv run ruff check --fix .` and `uv run ruff format .`.

Enable the Git hook once per clone with `uv run --locked pre-commit install`.
Before each commit, the hook runs Ruff lint, Ruff format, and the full pytest
suite in that order. If formatting changes a file, stage the changes and
retry the commit.

Set the release version with `uv version <version>`, which updates
`pyproject.toml` and `uv.lock`. Update `release/description.md` with the release
notes. After a push to `main` or `master`, GitHub Actions builds and checks the
distributions. A required reviewer must approve the `py-production` deployment
in Actions before the workflow creates the GitHub Release and publishes to PyPI.

## Getting support

- If you have a specific question about using this sdk, we encourage you
Expand Down
Loading
Loading