Python client for Prefab Feature Flags, Dynamic log levels, and Config as a Service: https://www.prefab.cloud
Project description
prefab-cloud-python
Python client for prefab.cloud, providing Config, FeatureFlags as a Service
Note: This library is under active development
Sign up to be notified about updates
Example usage
from prefab_cloud_python import Client, Options
options = Options(
prefab_api_key="your-prefab-api-key"
)
context = {
"user": {
"team_id": 432,
"id": 123,
"subscription_level": 'pro',
"email": "alice@example.com"
}
}
client = Client(options)
result = client.enabled("my-first-feature-flag", context=context)
print("my-first-feature-flag is:", result)
See full documentation https://docs.prefab.cloud/docs/sdks/python
Development
- Ensure that
poetry
is installed: https://python-poetry.org/docs/#installation - From the root of this directory, run
poetry install
to ensure dependencies are installed poetry run python
to open a Python REPL with access to the project dependencies
Running tests
To run all tests, including integration tests
poetry run pytest tests
To run only local tests and skip integration tests
poetry run pytest tests -k "not integration"
To run only one specific test file
poetry run pytest tests/name_of_test_file.py
Releasing
- Run pre-commit hooks to check and fix formatting, other rule enforcement.
poetry run pre-commit run --show-diff-on-failure --color=always --all-files
- On a branch
- Update the version in
pyproject.toml
- Update
CHANGELOG.md
- Update the version in
- Merge the branch
git tag <version> && git push --tags
poetry release --build
- To do this you will need an pypi.org account, and to be added to this project (ask Michael for an invitation)
StructLog Configuration
Simple Usage
There's a convenience method to access an opinionated structlog setup. No configuration of structlog is performed by default
from prefab_cloud_python import default_structlog_setup;
default_structlog_setup(colors=True) # true is the default, false to remove ANSI color codes
Using With Existing Structlog
We have a structlog processor that can be mixed into your existing structlog configuration.
The code below is an example configuration. See the note below about CallSiteParameterAdder
import structlog
from prefab_cloud_python import create_prefab_structlog_processor
from prefab_cloud_python import STRUCTLOG_CALLSITE_IGNORES
structlog.configure(
processors=[
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=False),
## ensure CallsiteparameterAdder is present before prefab_structlog_processor
structlog.processors.CallsiteParameterAdder(
[
structlog.processors.CallsiteParameter.PATHNAME,
structlog.processors.CallsiteParameter.FUNC_NAME,
],
additional_ignores=STRUCTLOG_CALLSITE_IGNORES,
),
create_prefab_structlog_processor(), ## add this
structlog.dev.ConsoleRenderer(),
]
)
CallSiteParameterAdder
We do require that CallSiteParameterAdder
is present and configured to handle PATHNAME
and FUNCNAME
in addition to any parameters you may be using
Please also merge our STRUCTLOG_CALLSITE_IGNORES
list into the additional_ignores
list as shown below
import structlog
from prefab_cloud_python import STRUCTLOG_CALLSITE_IGNORES
your_ignores = ["some", "ignores"]
structlog.processors.CallsiteParameterAdder(
[
structlog.processors.CallsiteParameter.PATHNAME,
structlog.processors.CallsiteParameter.FUNC_NAME,
],
additional_ignores=your_ignores + STRUCTLOG_CALLSITE_IGNORES,
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prefab_cloud_python-0.10.0b1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | eadb706d4696a2598303bbe8c4d3cc6654e0db0fa1b8172f85b13ab04ae6cc9a |
|
MD5 | e3694aad65163063c9be76960b8d5950 |
|
BLAKE2b-256 | 78cc7c8276dbc7284980be6ca0c6c4c8a94061dba75647581a053acc9a939fbd |
Hashes for prefab_cloud_python-0.10.0b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45abee2e7e8a0570026c9f94e3eda55bf83b18fa505beef3196cffb76f18362c |
|
MD5 | 00916e99662bd7498f6e542ffb6c9a77 |
|
BLAKE2b-256 | 89c8648cde129b901bc930b5c9af6117df79cdb8e1675c732f3dd0bbc78e8271 |