# 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](/feature-experimentation-and-rollout.md#server-side-experiments) .

See how to install the Flagship Python SDK in your project :[installation](/server-side/sdks/python/python-installation.md).

## 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:

```python
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](/server-side/decision-api.md). More options are available in the [SDK configuration](/server-side/sdks/python/python-reference.md#configure-your-python-sdk).

{% hint style="info" %}
📘 Environment ID and API Key

Environment id (*ENV\_ID*) and API key (*API\_KEY*) can be found on your Flagship account, in Parameters > Environment & Security.
{% endhint %}

## Step 2 : Create a visitor

When the SDK is Ready, creating a [visitor](/server-side/sdks/python/python-reference.md#create-new-visitors) using the [new\_visitor](/server-side/sdks/python/python-reference.md#create-new-visitors) function from the Flagship instance allows you to set relevant data for Flagship to make a decision, including: [Visitor ID](/server-side/glossary.md#visitor-id), [Visitor Context](/server-side/glossary.md#user-context-1), [GDPR Consent](https://github.com/flagship-io/Gitbook/blob/main/sdks/python-sdk/python-reference/README.md#manage-visitor-consent), and [Authentication status](/server-side/sdks/python/python-reference.md#keep-visitors-experience-continuity).

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.

```python
from flagship.config import DecisionApi
from flagship import *
from flagship.status_listener import StatusListener
from flagship.tracking_manager import TrackingManagerConfig
from flagship.hits import Screen

def init():

    class CustomStatusListener(StatusListener):

        def on_status_changed(self, new_status):
            if new_status is Status.READY:
                print(new_status)
                visitor = Flagship.new_visitor(visitor_id='visitor-A', context={'isVIP': True, "lastCheckout": 99})

    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()
```

## Step 3 : Manage flags

Once a visitor is created with a given context, you have to fetch flags, using the [fetch\_flags](/server-side/sdks/python/python-reference.md#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](/server-side/sdks/python/python-reference.md#use-your-flags) 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.

```python
from flagship.config import DecisionApi
from flagship import *
from flagship.status_listener import StatusListener
from flagship.tracking_manager import TrackingManagerConfig
from flagship.hits import Screen

def init():

    class CustomStatusListener(StatusListener):

        def on_status_changed(self, new_status):
            if new_status is Status.READY:
                print(new_status)
                visitor = Flagship.new_visitor(visitor_id='visitor-A', context={'isVIP': True, "lastCheckout": 99})
                visitor.fetch_flags()
                print(str(visitor.get_flag("my_flag", 'default').value()))

    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()
```

{% hint style="info" %}
📘 Flag exposure

The SDK assumes that the visitor has been exposed to the flag by default when `flag.value()` is called, so it sends the flag exposure hit on Flagship servers. This behavior can be changed and exposure be sent manually, [Click here for more details](/server-side/sdks/python/python-reference.md#expose-flags-to-user).
{% endhint %}

## Step 4 : Send tracking hit events

Finally, send hits to Flagship using the [send\_hit](/server-side/sdks/python/python-reference.md#send-tracking-hits) method of the [**visitor instance**](/server-side/sdks/python/python-reference.md#visitor-instance). These hits help validate your objectives (KPIs) set up in your campaign.\\

```python
from flagship.config import DecisionApi
from flagship import *
from flagship.status_listener import StatusListener
from flagship.tracking_manager import TrackingManagerConfig
from flagship.hits import Screen

def init():

    class CustomStatusListener(StatusListener):

        def on_status_changed(self, new_status):
            if new_status is Status.READY:
                print(new_status)
                visitor = Flagship.new_visitor(visitor_id='visitor-A', context={'isVIP': True, "lastCheckout": 99})
                visitor.fetch_flags()
                print(str(visitor.get_flag("my_flag", 'default').value()))
                visitor.send_hit(Screen("screen 1"))

    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()
```

## Step 5 : Reporting

{% hint style="success" %}
👍 Congrats, you have successfully implemented the Flagship Python SDK.

Check your campaign reporting.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/server-side/sdks/python/python-quick-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
