Skip to content

Conversation

@khvn26
Copy link
Member

@khvn26 khvn26 commented Jan 9, 2026

Contributes to Flagsmith/flagsmith#6341.

In this PR, we add types representing the SDK API request and response bodies to be used as

  1. source of truth when generating SDK API OpenAPI schemas.
  2. Type annotations for Flagsmith server implementations and Flagsmih client code written in Python.

The types are accompanied by docstrings carrying user-facing API documentation.

@khvn26 khvn26 requested a review from a team as a code owner January 9, 2026 12:14
@khvn26 khvn26 requested review from emyller and removed request for a team January 9, 2026 12:14
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.67%. Comparing base (94154b0) to head (6921024).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
+ Coverage   95.48%   95.67%   +0.19%     
==========================================
  Files          83       85       +2     
  Lines        2767     2891     +124     
==========================================
+ Hits         2642     2766     +124     
  Misses        125      125              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few edit suggestions. None blocking.

Comment on lines +56 to +57
priority: int | None
"""The priority of this segment feature override. Lower numbers indicate stronger priority. If null or not set, the weakest priority is assumed."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Comment on lines +93 to +97
property_: str
"""The property (context key) this condition applies to. May be `None` for the `PERCENTAGE_SPLIT` operator.

Named `property_` for legacy reasons.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth introducing a new attribute context_key and have property_ aliasing to it for backwards compatibility?



class Segment(TypedDict):
"""Represents a Flagsmith segment. Carries rules, feature overrides, and segment rules."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Represents a Flagsmith segment. Carries rules, feature overrides, and segment rules."""
"""Represents a dynamic group of identities matching the set of `rules`, which will be applied all overrides from `feature_states`."""



class Project(TypedDict):
"""Represents data about a Flagsmith project. For SDKs, this is mainly used to convey segment data."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Represents data about a Flagsmith project. For SDKs, this is mainly used to convey segment data."""
"""Represents a Flagsmith project. For SDKs, this is mainly used to convey segment data."""



class MultivariateFeatureStateValue(TypedDict):
"""Represents a multivariate feature state value."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Represents a multivariate feature state value."""
"""Represents a feature override that will apply to identities falling into the specified percentage of matched identities."""

mv_fs_value_uuid: UUIDStr | None
"""The UUID for this multivariate feature state value. Should be used for multivariate bucketing if `id` is null."""
percentage_allocation: float
"""The percentage allocation for this multivariate feature state value. Should be between or equal to 0 and 100."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""The percentage allocation for this multivariate feature state value. Should be between or equal to 0 and 100."""
"""The percentage allocation for this multivariate feature state value. Should be between or equal to 0 and 100; total percentage allocation of grouped `MultivariateFeatureStateValue` must not exceed 100."""

Comment on lines +33 to +37
class MultivariateFeatureOption(TypedDict):
"""Represents a single multivariate feature option in the Flagsmith UI."""

value: str
"""The feature state value that should be served when this option's parent multivariate feature state is selected by the engine."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope, but is worth a note: I think this entity makes no sense in the API. I understand this represents the data model, but it also makes the API schema slightly harder to grasp as it adds hierarchy with no value.



class FeatureState(TypedDict):
"""Used to define the state of a feature for an environment, segment overrides, and identity overrides."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Used to define the state of a feature for an environment, segment overrides, and identity overrides."""
"""A feature override for an environment, a segment, or an identity."""



class SegmentRule(TypedDict):
"""Represents a rule within a segment used by Flagsmith engine."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Represents a rule within a segment used by Flagsmith engine."""
"""Represents a group of logic conditions to match identities with; root segment rules may contain sub rules."""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants