Metadata-Version: 2.4
Name: splitio_configs
Version: 1.0.0b5
Summary: Harness.io Python Configs Client
Home-page: https://github.com/splitio/python-configs-client
Download-URL: https://github.com/splitio/python-configs-client/tarball/1.0.0-beta5
Author: Bilal Al-Shahwany
Author-email: bilal.al-shahwany@harness.io
License: Apache License 2.0
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: splitio-commons==2.0.0
Provides-Extra: test
Requires-Dist: flake8; extra == "test"
Requires-Dist: pytest==7.0.1; python_version < "3.9" and extra == "test"
Requires-Dist: pytest<9,>=8.4; python_version >= "3.9" and extra == "test"
Requires-Dist: pytest-mock==3.11.1; python_version < "3.9" and extra == "test"
Requires-Dist: pytest-mock>=3.14; python_version >= "3.9" and extra == "test"
Requires-Dist: coverage==7.0.0; python_version < "3.9" and extra == "test"
Requires-Dist: coverage>=7.6; python_version >= "3.9" and extra == "test"
Requires-Dist: pytest-cov==4.1.0; python_version < "3.9" and extra == "test"
Requires-Dist: pytest-cov>=6; python_version >= "3.9" and extra == "test"
Requires-Dist: importlib-metadata==6.7; python_version < "3.9" and extra == "test"
Requires-Dist: tomli==1.2.3; python_version < "3.9" and extra == "test"
Requires-Dist: iniconfig==1.1.1; python_version < "3.9" and extra == "test"
Requires-Dist: attrs==22.1.0; python_version < "3.9" and extra == "test"
Requires-Dist: urllib3==2.0.7; python_version < "3.9" and extra == "test"
Requires-Dist: pytest-asyncio==0.21.0; python_version < "3.9" and extra == "test"
Requires-Dist: pytest-asyncio==0.21.2; python_version >= "3.9" and extra == "test"
Requires-Dist: aiohttp>=3.8.4; extra == "test"
Requires-Dist: aiofiles>=23.1.0; extra == "test"
Provides-Extra: asyncio
Requires-Dist: aiohttp>=3.8.4; extra == "asyncio"
Requires-Dist: aiofiles>=23.1.0; extra == "asyncio"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: download-url
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Harness FME Python Configs SDK

[![PyPI version](https://badge.fury.io/py/splitio_configs.svg)](https://badge.fury.io/py/splitio_configs)

## Overview

Harness FME Python Configs SDK is designed to serve standalone, versioned configuration objects in Python applications.

## Compatibility

This SDK is compatible with **Python 3.7 and higher**.

## Getting started

Install the SDK:

```bash
pip install splitio_configs
```

Below is a simple example that describes the instantiation and most basic usage of our SDK:

```python
from splitio_configs import ConfigsClient, TimeoutException, Target

client = ConfigsClient('YOUR_SDK_KEY')
try:
    client.block_until_ready()
except TimeoutException:
    # SDK_READY_TIMED_OUT: evaluations will return the fallback config or a Config with variant "control".
    pass

# Without target: returns the default variant of the config
default_config = client.get_config('CONFIG_NAME')
print(default_config.variant)  # example: 'v1'
print(default_config.value)    # example: {'prompt': 'Hello world', 'temperature': 0.5}

# With target: evaluates targeting rules for the given key
target = Target('user-123')
config = client.get_config('CONFIG_NAME', target)
print(config.variant, config.value)

# On shutdown: blocks until pending impressions and events are flushed
client.destroy()
```

The SDK also supports asyncio, as shown in the example below:
```python
import asyncio
from splitio_configs import ConfigsClientAsync, TimeoutException, Target

async def main():
    client = ConfigsClientAsync('YOUR_SDK_KEY')
    try:
        await client.block_until_ready()
    except TimeoutException:
        # SDK_READY_TIMED_OUT: evaluations will return the fallback config or a Config with variant "control".
        pass

    # Without target: returns the default variant of the config
    default_config = await client.get_config('CONFIG_NAME')
    print(default_config.variant)  # example: 'v1'
    print(default_config.value)    # example: {'prompt': 'Hello world', 'temperature': 0.5}

    # With target: evaluates targeting rules for the given key
    target = Target('user-123')
    config = await client.get_config('CONFIG_NAME', target)
    print(config.variant, config.value)

    # On shutdown: waits until pending impressions and events are flushed
    await client.destroy()

asyncio.run(main())
```

## AI Configs

The SDK supports the `get_ai_config` method to fetch AI agent configurations. The AI config value is parsed with the parser you pass: the SDK ships a built-in `LlmCallParser`, and you can also pass your own `Parser` implementation.

Example using the built-in parser:
```python
from splitio_configs import ConfigsClient, TimeoutException, Target, LlmCallParser

client = ConfigsClient('YOUR_SDK_KEY')
try:
    client.block_until_ready()
except TimeoutException:
    # SDK_READY_TIMED_OUT: evaluations will return the fallback config or a Config with variant "control".
    pass

parser = LlmCallParser()

# With target: evaluates targeting rules for the given key
target = Target('user-123')
ai_config = client.get_ai_config('CONFIG_NAME', parser, target)
# config standard data
print(ai_config.variant, ai_config.value)
# ai config data (parsed_value is None for the "control" variant)
if ai_config.parsed_value is not None:
    llm_call = ai_config.parsed_value
    print(llm_call.provider)
    print(llm_call.model)
```

Example using a custom parser:
```python
from splitio_configs import ConfigsClient, TimeoutException, Target, Parser

class MyLlmCall(object):
    def __init__(self, model, temperature):
        self.model = model
        self.temperature = temperature

class MyParser(Parser):
    def parse(self, source):
        return MyLlmCall(source.value.get("model"), source.value.get("temperature"))

client = ConfigsClient('YOUR_SDK_KEY')
try:
    client.block_until_ready()
except TimeoutException:
    # SDK_READY_TIMED_OUT: evaluations will return the fallback config or a Config with variant "control".
    pass

my_parser = MyParser()

# With target: evaluates targeting rules for the given key
target = Target('user-123')
ai_config = client.get_ai_config('CONFIG_NAME', my_parser, target)
# config standard data
print(ai_config.variant, ai_config.value)
# ai config data (parsed_value is None for the "control" variant)
if ai_config.parsed_value is not None:
    print(ai_config.parsed_value.model)
    print(ai_config.parsed_value.temperature)
```

`parse()` receives a `ParseSource` wrapping the evaluated config; read the variant value (a JSON object) from `source.value`. More fields may be added to `ParseSource` later without changing the `Parser` interface.

Any `Parser` instance is accepted, so custom parsers can inherit from your own base classes. A class that cannot inherit from `Parser` can be registered as a virtual subclass with `Parser.register(MyParser)`.

Please refer to [our official docs](https://developer.harness.io/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/server-side-configs-sdks/python-sdk) to learn about all the functionality provided by our SDK and the configuration options available for tailoring it to your current application setup.

## Submitting issues

The Split team monitors all issues submitted to this [issue tracker](https://github.com/splitio/python-configs-client/issues). We encourage you to use this issue tracker to submit any bug reports, feedback, and feature enhancements. We'll do our best to respond in a timely manner.

## License

Licensed under the Apache License, Version 2.0. See: [Apache License](http://www.apache.org/licenses/).
