Skip to content

v0.2.0

Latest

Choose a tag to compare

@thephw thephw released this 27 Oct 20:01
132c459

Per-actor feature flags (#24)

Turn a flag on for particular users or groups without enabling it for everyone.

client.enable_actor("new_ui", "user:42")    # or any object with a feature_gate_id attribute
client.disable_actor("new_ui", "org:7")
client.actors("new_ui")                     # ids in the order they were added
client.is_enabled("new_ui", user, user.org) # globally on, or on for any actor passed
  • Actors are namespaced strings ("user:42", "org:7") or objects with a feature_gate_id attribute. Bare integers are rejected so user 42 and org 42 can't collide. is_enabled skips None actors.
  • is_enabled(key, *actors) is true when the flag is on globally or for any actor passed. Pass a user together with their groups.
  • disable() only turns off the global switch; actors keep the flag until disable_actor().
  • PostgresAdapter: new <prefix>feature_actors table (migration 0002_create_feature_actors).
  • PosthogAdapter: actors are stored as a distinct_id release condition on the flag and evaluated by feature_gate. Other conditions you set up in PostHog are left alone, and enable_actor raises ValueError rather than activating an inactive flag that has them. Behavior without actors is unchanged.
  • See the Actors section of the README.

Upgrading

  • PostgresAdapter users: run feature-gate-migrate after upgrading. is_enabled(key) without actors keeps working until you do, but the actor methods need the new table.
  • On PostHog, disable() on a flag with actors keeps the flag active for those actors, so any other conditions on it keep running.

Full Changelog: v0.1.1...v0.2.0