Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,41 @@ jobs:
strategy:
matrix:
os: [ "ubuntu-latest" ]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.12', '3.14']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install library
- name: Install project
run: poetry install --no-interaction
- name: Test with pytest
run: poetry run pytest --cov=flagship --cov-report=xml ./tests/
- name: Upload coverage
if: matrix.python-version == 3.8
if: matrix.python-version == 3.9
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: false
- name: Build and publish library
if: matrix.python-version == 3.8
if: matrix.python-version == 3.9
run: |
poetry build
poetry build
11 changes: 5 additions & 6 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ jobs:
strategy:
matrix:
os: [ "ubuntu-latest" ]
python-version: ['3.8', '3.9', '3.10', '3.11']
# python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.12', '3.14']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
Expand All @@ -27,7 +26,7 @@ jobs:
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
Expand All @@ -39,7 +38,7 @@ jobs:
- name: Test with pytest
run: poetry run pytest --cov=flagship --cov-report=xml ./tests/
- name: Upload coverage
if: matrix.python-version == 3.8
if: matrix.python-version == 3.9
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
Expand Down
9 changes: 5 additions & 4 deletions flagship/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
from flagship.visitor import Visitor

__name__ = 'flagship'
__version__ = importlib_metadata.distribution(__name__).version

try:
from importlib.metadata import distribution
__version__ = distribution(__name__).version
except Exception:
__version__ = "0.0.0-dev"

class Flagship:
__instance = None
Expand Down Expand Up @@ -115,12 +118,10 @@ def __init__(self):

@param_types_validator(True, str, str, [_FlagshipConfig, None])
def start(self, env_id, api_key, flagship_config):
# self.update_status(flagship_config, Status.STARTING)
if not env_id or not api_key:
raise InitializationParamError()
self.update_status(flagship_config, Status.STARTING)
self.configuration_manager.init(env_id, api_key, flagship_config, self.update_status)
# self.update_status(flagship_config, Status.STARTING)
if self.configuration_manager.is_set() is False:
self.update_status(self.configuration_manager.flagship_config, Status.NOT_INITIALIZED)
self.__log(TAG_INITIALIZATION, LogLevel.ERROR, ERROR_CONFIGURATION)
Expand Down
2 changes: 1 addition & 1 deletion flagship/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def __init__(self, mode, **kwargs):
self.log_manager = self.get_arg(kwargs, 'log_manager', LogManager) or FlagshipLogManager(self.log_level)
self.polling_interval = self.get_arg(kwargs, 'polling_interval', type(1)) or 60000
self.timeout = self.get_arg(kwargs, 'timeout', type(1)) or 2000
self.status_listener = self.get_arg(kwargs, 'status_listener', StatusListener) or None
self.tracking_manager_config = self.get_arg(kwargs, 'tracking_manager_config',
TrackingManagerConfig) or TrackingManagerConfig()
self.cache_manager = self.get_arg(kwargs, 'cache_manager', CacheManager) or None
self.status_listener = self.get_arg(kwargs, 'status_listener', StatusListener) or None

def get_arg(self, kwargs, name, c_type):
return kwargs[name] if name in kwargs and isinstance(kwargs[name], c_type) else None
Expand Down
7 changes: 1 addition & 6 deletions flagship/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def init(self, env_id, api_key, config=None, update_status=None):
self.flagship_config.log_manager.log(TAG_INITIALIZATION, LogLevel.WARNING, WARNING_DEFAULT_CONFIG)
self.flagship_config.env_id = env_id
self.flagship_config.api_key = api_key
self.init_decision_manager(update_status)
self.init_cache_manager()
self.init_tracking_manager()
self.init_decision_manager(update_status)
self.decision_manager.start_running()

def init_decision_manager(self, update_status=None):
Expand All @@ -39,21 +39,16 @@ def init_decision_manager(self, update_status=None):

def init_cache_manager(self):
try:
# if self.cache_manager is None:
# self.cache_manager = CacheManager()
if self.flagship_config.cache_manager is not None:
self.cache_manager = self.flagship_config.cache_manager
self.cache_manager.init(self.flagship_config)
# if self.flagship_config.cache_manager is not None:
# self.flagship_config.cache_manager.init(env_id)
except Exception as e:
print(e)

def init_tracking_manager(self):
if self.tracking_manager is None:
self.tracking_manager = TrackingManager(self.flagship_config, self.cache_manager)
self.tracking_manager.init(self.flagship_config, self.cache_manager)
# self.tracking_manager.start_running()

def is_set(self):
return self.flagship_config.is_set() and self.decision_manager is not None
Expand Down
8 changes: 7 additions & 1 deletion flagship/hits.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,16 @@ def __init__(self, visitor_id, context):
Hit.__init__(self, HitType.SEGMENT)
data = {
HitFields.visitor_id: visitor_id,
HitFields.segment_list: context
HitFields.segment_list: self.stringify_values(context)
}
self.hit_data.update(data)

def stringify_values(self, obj):
new_obj = {}
for key, value in obj.items():
new_obj[key] = str(value)
return new_obj

def check_data_validity(self):
if ((Hit.check_data_validity(self) is False) or
(not bool(self.hit_data[HitFields.visitor_id])) or
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "flagship"
version = "3.0.0"
version = "3.0.1"
description = "Flagship Python SDK"
authors = ["Raphael <[email protected]>"]
license = "Apache License Version 2.0"
Expand All @@ -20,7 +20,7 @@ pytest-cov = "^4.1.0"

[tool.poetry.urls]
Sources = "https://github.com/abtasty/flagship-python-sdk"
Documentation = "https://docs.developers.flagship.io/docs/python"
Documentation = "https://docs.abtasty.com/server-side/sdks/python"

[build-system]
requires = ["poetry-core"]
Expand Down
50 changes: 27 additions & 23 deletions script.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import asyncio
import sys
import time

from flagship.config import DecisionApi
from flagship import *
from flagship.cache_manager import SqliteCacheManager
from flagship.config import DecisionApi, Bucketing
from flagship.hits import Screen
from flagship.config import Bucketing
from flagship.status_listener import StatusListener
from flagship.tracking_manager import TrackingManagerConfig

from flagship.hits import Screen

def init():
print(sys.version)
Flagship.start('__env_id__', '__api_key__', DecisionApi(timeout=3000,
cache_manager=SqliteCacheManager(),
log_level=LogLevel.ALL,
tracking_manager_config=TrackingManagerConfig(
time_interval=10000,
max_pool_size=5))) ## Demo

visitor = Flagship.new_visitor('visitor-A', context={'testing_tracking_manager': True})
visitor.fetch_flags()
visitor.get_flag("my_flag", 'default').value()
visitor.send_hit(Screen("screen 1"))
time.sleep(2)




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, "int": 4973})
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)

init()
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ classifiers =
Operating System :: OS Independent
author = Flagship Team
author_email = [email protected]
url = https://docs.developers.flagship.io/docs/python-v2-1
url = https://docs.abtasty.com/server-side/sdks/python
project_urls =
Sources = https://github.com/abtasty/flagship-python-sdk
Documentation = https://docs.developers.flagship.io/docs/python-v2-1
Documentation = https://docs.abtasty.com/server-side/sdks/python
[options]
python_requires = >=3.7
packages = find:
Expand Down