Quick start
The following example assumes that a campaign has already been configured beforehand on the platform and that the Python SDK has been successfully installed in your project.
See how to configure a toggle feature campaign on our user documentation .
See how to install the Flagship Python SDK in your project :installation.
Step 1 : Initialize the SDK
At the most appropriate location of your python application, call the start function from the Flagship class, in order to initialize the Flagship SDK:
from flagship import *
from flagship.config import DecisionApi
def init():
class CustomStatusListener(StatusListener):
def on_status_changed(self, new_status):
if new_status == Status.READY:
print('SDK READY')
Flagship.start(
'_ENV_ID_',
'_API_KEY_',
DecisionApi(
timeout=3000,
status_listener=CustomStatusListener(),
log_level=LogLevel.ALL,
tracking_manager_config=TrackingManagerConfig(time_interval=5000, max_pool_size=5)
)
)
time.sleep(6) ### Mock runtime
init()The SDK starts in DECISION-API. More options are available in the SDK configuration.
Step 2 : Create a visitor
When the SDK is Ready, creating a visitor using the new_visitor function from the Flagship instance allows you to set relevant data for Flagship to make a decision, including: Visitor ID, Visitor Context, GDPR Consent, and Authentication status.
For example, if you want to enable a specific feature for all your VIP visitors, you'll need to add this data as an attribute into the visitor context (key-value pair): isVIP: true.
Based on your targeting criteria defined in your use-case (isVIP == true), Flagship will make the decision and show your feature to visitors when they have isVIP: true in their context.
Step 3 : Manage flags
Once a visitor is created with a given context, you have to fetch flags, using the fetch_flags method, to assign campaigns and its flags to this visitor.
When flag fetching completes, you are ready to process visitor's flags and read their values from the returned Flag object based on the desired flag key.
This object includes methods to retrieve the flag value, its metadata, expose the flag, verify the flag's existence, and get the flag status.
Step 4 : Send tracking hit events
Finally, send hits to Flagship using the send_hit method of the visitor instance. These hits help validate your objectives (KPIs) set up in your campaign.\
Step 5 : Reporting
👍 Congrats, you have successfully implemented the Flagship Python SDK.
Check your campaign reporting.
Last updated
Was this helpful?

