Feature flags, with a GUI - SQL Alchemy backend
Project description
flypper-sqlalchemy
Flypper-sqlalchemy is a storage backend for the flypper package.
It is backed by a RDBMS through the SQL-Alchemy library so it an be used in a distributed environment and be persisted across restarts.
Installation
Use the package manager pip to install flypper-sqlalchemy
.
pip install flypper-sqlalchemy
Usage
Build a storage backend:
from flypper_sqlalchemy.storage.sqla import SqlAlchemyStorage
# Create tables, make sure they are created, for instance with `create_all()`.
SqlAlchemyStorage.build_flags_table(sqla_metadata=metadata)
SqlAlchemyStorage.build_metadata_table(sqla_metadata=metadata)
storage = SqlAlchemyStorage(session=session_proxy)
# Or instead, depending on the use-case:
#
# storage = SqlAlchemyStorage(engine=engine)
)
Use it in the web UI:
from flypper.wsgi.web_ui import FlypperWebUI
web_ui = FlypperWebUI(storage=storage)
Use it in your code:
- Build a client for your app
- Use a context
from flypper.client import Client as FlypperClient
# Once per thread
flypper_client = FlypperClient(storage=storage, ttl=10)
# Once per request
flypper_context = FlypperContext(
client=flypper_client,
entries={"user_id": "42"},
)
# Every time you need
flypper_context.is_enabled("flag_name")
flypper_context.is_enabled(
"other_flag_name",
entries={"item_reference": "blue-shampoo"},
)
Q&A
How to use the ORM layer of SQL-Alchemy?
We can use the Hybrid Declarative mapping capability to build a mapped class from flypper's tables:
from sqlalchemy.ext.declarative import declarative_base
from flypper_sqlalchemy.storage.sqla import SqlAlchemyStorage
Base = declarative_base()
class FlypperFlag(Base):
__table__ = SqlAlchemyStorage.build_flags_table(
sqla_metadata=Base.metadata,
)
class FlypperMetadata(Base):
__table__ = SqlAlchemyStorage.build_metadata_table(
sqla_metadata=Base.metadata,
)
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Project details
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 flypper_sqlalchemy-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f03436f5562eba3158e89cf30178b0aad74bc5a00cb0a96406e55beb1dcd8d92 |
|
MD5 | ceafce99f046eedb83b5ffaa3664169e |
|
BLAKE2b-256 | 73237871e175d9b0b9e7d818a4d04671f656c8f0b96bc67ce8817436916b5f17 |