Skip to main content

A small package for creating and using configurations to control code flow

Project description

PyGating

PyGating is a small but simple python library that enables you to quickly introduce a/b testing, control code flow, and introduce control switches to your codebase that can be controlled via both code and json-based configs.

PyGating supports entity-based checks, allowing you to define in the gating configuration exactly the properties, functions, and/or keys the gate will check based on a entity you will pass in at check time.

Check out the respository here for more information and documentation

Features

  • Extensible Framework: Create custom gates by extending base gate classes.
  • Entity-based gates: Define gate configurations based on entity properties/functions to make gates dynamic
  • Consistant Hashing: Entity-based gate checks will pass/fail consistently based on property hashing
  • JSON Configuration: Supports gate configuration defined in json so that you can pull gates configs from databases
  • Predefined Gates: Includes DateGate, PercentageGate, RandomGate, InclusionGate, and more.
  • Custom Gate Configurations: Combine gates to create complex gating logic.

Quick Usage Example

This example will only permit 10% of entities/code invocations to continue.

We can use either a RandomGate for pure 10% random chance or a PercentageGate for a consistant result based on the passed entity

  • Initialize Pygating Library and imports
from pygating import PyGating
from pygating.gating_configurations import GatingConfigurationAll
from pygating.gates import PercentageGate

PyGating.init() # only needs to be done once in the application
  • Define a gate config (code or json):

Code-based config

gate_config = GatingConfigurationAll(
    fail_closed=True, #if an exception is thrown, the gate check returns False
    gates=[
        PercentageGate(percentage=10, allow=True, entity_property="id") # 10% of entities passed into the gate check will pass based on their id field 
    ]
)
or

Json-based config

gate_config = {
    "type": "GatingConfigurationAll",
    "fail_closed": True,
    "gates": [
        {
            "type": "PercentageGate",
            "percentage": 10.0,
            "allow": True,
            "entity_property": "id"
        }
    ]
}
  • Use gate in your code:
class Entity:
    def __init__(self, id: str):
        self.id = id

example_entity = Entity(id="dfa2oi1nrffvnoivwe")

if PyGating.check_gating(gate_config, entity=entity):
    print("Gate passed!") # Will pass for 10% of entity ids, and will be consistent for the same ids
else:
    print("Gate Failed")

Installation

pip install pygating

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

pygating-1.0.3.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygating-1.0.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file pygating-1.0.3.tar.gz.

File metadata

  • Download URL: pygating-1.0.3.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pygating-1.0.3.tar.gz
Algorithm Hash digest
SHA256 17c2746745d4e1bc6cca44286bdd363348746fe87e2108e4ce10e0706f78319e
MD5 9f2f46ac156a60f73a5c7ad669a31ac0
BLAKE2b-256 67ed9f24c19b2c21f1f90d304b01d58685a4af81ea1b75f1e7a250e19ec7a8e8

See more details on using hashes here.

File details

Details for the file pygating-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pygating-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pygating-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d4f008424bb0b15c572b54c2c97b478e4295cbabe24c59bb24aa5296e32447eb
MD5 0f12c77e1d9a814bab332a6e25284ed3
BLAKE2b-256 1adac8f9736ef3568c94f56d5584175ce8cab9a0e9317bf76985c9f451bf12d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page