joystick-python


Namejoystick-python JSON
Version 0.1.0a1 PyPI version JSON
download
home_pagehttps://github.com/getjoystick/getjoystick/joystick-python
SummaryJoystick is a modern remote configuration and dynamic content service designed specifically for operating apps and games. Upgrade to more agility and evolve your product faster. Change or hot-update your content and configurations instantly at scale without code. Segment, ab test, feature flag, schedule events and more. Joystick is a breeze to use yet powerful.
upload_time2023-03-31 15:35:45
maintainer
docs_urlNone
authorJoystick
requires_python>=3.6
licenseMIT
keywords remote configuration feature flagging dynamic content remote configs live-ops game ops ab testing segmentation dynamic json update json remote json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pythong client for [Joystick](https://www.getjoystick.com/)

[![GitHub Actions](https://github.com/getjoystick/joystick-python/actions/workflows/on-publishing.yml/badge.svg)](<(https://github.com/getjoystick/joystick-python/actions?query=branch%3Amain)>)
[![Latest Stable Version](https://img.shields.io/pypi/v/joystick-python.svg)](https://pypi.org/project/joystick-python)
[![PyPI Wheel](https://img.shields.io/pypi/wheel/joystick-python.svg)](https://pypi.org/project/joystick-python)
[![Supported versions](https://img.shields.io/pypi/pyversions/joystick-python.svg)](https://pypi.org/project/joystick-python)
[![Supported implementations](https://img.shields.io/pypi/implementation/joystick-python.svg)](https://pypi.org/project/joystick-python)
[![License](https://img.shields.io/pypi/l/joystick-python.svg)](https://pypi.org/project/joystick-python)

This is the library that simplifies the way how you can communicate with [Joystick API](https://docs.getjoystick.com/).

## Installation

You can install the package via [Pip](https://pip.pypa.io/en/stable/installation/):

```bash
pip install joystick-python
```

## Usage

We provide two types of clients: asynchronous and synchronous. They have exactly the same interfaces,
the only difference is a way you import them.

### Async / Sync

#### Sync

```python
import os

from joystick import Client

joystick_api_key = os.getenv("JOYSTICK_API_KEY")

if joystick_api_key is None:
    raise ValueError("Please set JOYSTICK_API_KEY environment variable.")

client = Client(
    api_key=joystick_api_key,
)

response = client.get_contents({"cid1", "cid2"})

print(f'First content: {response["cid1"]}')
print(f'Second content: {response["cid2"]}')
```

#### Async

```python
import asyncio
import os

from joystick import AsyncClient


async def main():
    joystick_api_key = os.getenv("JOYSTICK_API_KEY")

    if joystick_api_key is None:
        raise ValueError("Please set JOYSTICK_API_KEY environment variable.")

    client = AsyncClient(
        api_key=joystick_api_key,
    )

    response = await client.get_contents({"cid1", "cid2"})

    print(f'First content: {response["cid1"]}')
    print(f'Second content: {response["cid2"]}')


asyncio.run(main())

```

> All examples below will be provided for `async` version of the client. For sync it's enough to
> use proper Client and avoid `await` keyword

### Requesting content by single Content Id

```python
...
await client.get_content('cid1')
...
```

### Specifying additional parameter

When creating the `Client`/`AsyncClient` instance, you can specify additional parameters which will
be used by all API calls from the client, for more details see
[API documentation](https://docs.getjoystick.com/api-reference/):

```python
client = AsyncClient(
    api_key=joystick_api_key,
    cache_expiration_seconds=60,
    serialized=True,
    params={
        "param1": "value1",
        "param2": "value2",
    },
    sem_ver="0.0.1",
    user_id="user-id-1",
)
```

### Options

#### `full_response`

In most of the cases you will be not interested in the full response from the API, but if you're you can specify
`fullResponse` option to the client methods. The client will return you raw API response:

```python
get_content_response = await client.get_content('cid1', full_response=True)
# OR
get_contents_response = await client.get_contents({'cid1'}  , full_response=True)
```

#### `serialized`

When `true`, we will pass query parameter `responseType=serialized`
to [Joystick API](https://docs.getjoystick.com/api-reference-combine/).

```python
get_content_response = await client.get_content('cid1', serialized=True)
# OR
get_contents_response = await client.get_contents({'cid1'}  , serialized=True)
```

This option can be set for every API call from the client by setting `serialized` as `true` via
constructor, or via propert setter.

```python
client = AsyncClient(
    api_key=joystick_api_key,
    serialized=True,
)
```

#### `refresh`

If you want to ignore existing cache and request the new config – pass this option as `true`.

```python
get_content_response = await client.get_content('cid1', refresh=True)
# OR
get_contents_response = await client.get_contents({'cid1'}  , refresh=True)
```

### Caching

By default, the client uses [in-memory caching](./src/joystick/_async/cache/in_memory.py),
which means that if you build the distributed application, every instance will go to the Joystick
API for at least first call and the cache will be erased after the application is closed.

You can specify your cache implementation which implements either
[`AsyncCacheInterface`](./src/joystick/_async/cache/cache.py) if you use `AsyncClient`,
or [`SyncCacheInterface`](./src/joystick/_sync/cache/cache.py) if you use `SyncClient`.

### Async support

We rely on library [`httpx`](https://www.python-httpx.org/) to make requests to Joystick API and we
support the [same platforms as `httpx`](https://www.python-httpx.org/async/#supported-async-environments).

#### Clear the cache

If you want to clear the cache – run `await client.clear_cache()`.

## Library development

We use the `pyenv` to install multiple versions of Python on the developer's machine and `venv` to create the virtual environment for these versions:

```bash
pyenv global 3.5.10
rm -rf ./venv # This one might fail, if it's the first time you create `venv` in this proj.
python3 -m venv venv
source ./venv/bin/activate
pip install -e '.[dev]'
```

### Run unit tests

```bash
nox -e test
```

### Very code style and format

```bash
nox -e format
```
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0-alpha.1]

### Added

-   Source code with the implementation of `get_contents` and `get_content`
-   [Examples](./examples)
-   Documentation [(README.md)](./README.md)
-   [GitHub Actions pipeline](https://github.com/getjoystick/joystick-python/tree/main/.github/workflows) to check code style + Unit Testing at different Python versions + different platforms

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/getjoystick/getjoystick/joystick-python",
    "name": "joystick-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "Remote configuration,feature flagging,dynamic content,remote configs,live-ops,game ops,ab testing,segmentation,dynamic json,update json,remote json",
    "author": "Joystick",
    "author_email": "letsgo@getjoystick.com",
    "download_url": "https://files.pythonhosted.org/packages/89/16/21d430e810f5fdbe1eac1c1b67350c477667318e9ca7fee92e09ef46066e/joystick-python-0.1.0a1.tar.gz",
    "platform": null,
    "description": "# Pythong client for [Joystick](https://www.getjoystick.com/)\n\n[![GitHub Actions](https://github.com/getjoystick/joystick-python/actions/workflows/on-publishing.yml/badge.svg)](<(https://github.com/getjoystick/joystick-python/actions?query=branch%3Amain)>)\n[![Latest Stable Version](https://img.shields.io/pypi/v/joystick-python.svg)](https://pypi.org/project/joystick-python)\n[![PyPI Wheel](https://img.shields.io/pypi/wheel/joystick-python.svg)](https://pypi.org/project/joystick-python)\n[![Supported versions](https://img.shields.io/pypi/pyversions/joystick-python.svg)](https://pypi.org/project/joystick-python)\n[![Supported implementations](https://img.shields.io/pypi/implementation/joystick-python.svg)](https://pypi.org/project/joystick-python)\n[![License](https://img.shields.io/pypi/l/joystick-python.svg)](https://pypi.org/project/joystick-python)\n\nThis is the library that simplifies the way how you can communicate with [Joystick API](https://docs.getjoystick.com/).\n\n## Installation\n\nYou can install the package via [Pip](https://pip.pypa.io/en/stable/installation/):\n\n```bash\npip install joystick-python\n```\n\n## Usage\n\nWe provide two types of clients: asynchronous and synchronous. They have exactly the same interfaces,\nthe only difference is a way you import them.\n\n### Async / Sync\n\n#### Sync\n\n```python\nimport os\n\nfrom joystick import Client\n\njoystick_api_key = os.getenv(\"JOYSTICK_API_KEY\")\n\nif joystick_api_key is None:\n    raise ValueError(\"Please set JOYSTICK_API_KEY environment variable.\")\n\nclient = Client(\n    api_key=joystick_api_key,\n)\n\nresponse = client.get_contents({\"cid1\", \"cid2\"})\n\nprint(f'First content: {response[\"cid1\"]}')\nprint(f'Second content: {response[\"cid2\"]}')\n```\n\n#### Async\n\n```python\nimport asyncio\nimport os\n\nfrom joystick import AsyncClient\n\n\nasync def main():\n    joystick_api_key = os.getenv(\"JOYSTICK_API_KEY\")\n\n    if joystick_api_key is None:\n        raise ValueError(\"Please set JOYSTICK_API_KEY environment variable.\")\n\n    client = AsyncClient(\n        api_key=joystick_api_key,\n    )\n\n    response = await client.get_contents({\"cid1\", \"cid2\"})\n\n    print(f'First content: {response[\"cid1\"]}')\n    print(f'Second content: {response[\"cid2\"]}')\n\n\nasyncio.run(main())\n\n```\n\n> All examples below will be provided for `async` version of the client. For sync it's enough to\n> use proper Client and avoid `await` keyword\n\n### Requesting content by single Content Id\n\n```python\n...\nawait client.get_content('cid1')\n...\n```\n\n### Specifying additional parameter\n\nWhen creating the `Client`/`AsyncClient` instance, you can specify additional parameters which will\nbe used by all API calls from the client, for more details see\n[API documentation](https://docs.getjoystick.com/api-reference/):\n\n```python\nclient = AsyncClient(\n    api_key=joystick_api_key,\n    cache_expiration_seconds=60,\n    serialized=True,\n    params={\n        \"param1\": \"value1\",\n        \"param2\": \"value2\",\n    },\n    sem_ver=\"0.0.1\",\n    user_id=\"user-id-1\",\n)\n```\n\n### Options\n\n#### `full_response`\n\nIn most of the cases you will be not interested in the full response from the API, but if you're you can specify\n`fullResponse` option to the client methods. The client will return you raw API response:\n\n```python\nget_content_response = await client.get_content('cid1', full_response=True)\n# OR\nget_contents_response = await client.get_contents({'cid1'}  , full_response=True)\n```\n\n#### `serialized`\n\nWhen `true`, we will pass query parameter `responseType=serialized`\nto [Joystick API](https://docs.getjoystick.com/api-reference-combine/).\n\n```python\nget_content_response = await client.get_content('cid1', serialized=True)\n# OR\nget_contents_response = await client.get_contents({'cid1'}  , serialized=True)\n```\n\nThis option can be set for every API call from the client by setting `serialized` as `true` via\nconstructor, or via propert setter.\n\n```python\nclient = AsyncClient(\n    api_key=joystick_api_key,\n    serialized=True,\n)\n```\n\n#### `refresh`\n\nIf you want to ignore existing cache and request the new config \u2013 pass this option as `true`.\n\n```python\nget_content_response = await client.get_content('cid1', refresh=True)\n# OR\nget_contents_response = await client.get_contents({'cid1'}  , refresh=True)\n```\n\n### Caching\n\nBy default, the client uses [in-memory caching](./src/joystick/_async/cache/in_memory.py),\nwhich means that if you build the distributed application, every instance will go to the Joystick\nAPI for at least first call and the cache will be erased after the application is closed.\n\nYou can specify your cache implementation which implements either\n[`AsyncCacheInterface`](./src/joystick/_async/cache/cache.py) if you use `AsyncClient`,\nor [`SyncCacheInterface`](./src/joystick/_sync/cache/cache.py) if you use `SyncClient`.\n\n### Async support\n\nWe rely on library [`httpx`](https://www.python-httpx.org/) to make requests to Joystick API and we\nsupport the [same platforms as `httpx`](https://www.python-httpx.org/async/#supported-async-environments).\n\n#### Clear the cache\n\nIf you want to clear the cache \u2013 run `await client.clear_cache()`.\n\n## Library development\n\nWe use the `pyenv` to install multiple versions of Python on the developer's machine and `venv` to create the virtual environment for these versions:\n\n```bash\npyenv global 3.5.10\nrm -rf ./venv # This one might fail, if it's the first time you create `venv` in this proj.\npython3 -m venv venv\nsource ./venv/bin/activate\npip install -e '.[dev]'\n```\n\n### Run unit tests\n\n```bash\nnox -e test\n```\n\n### Very code style and format\n\n```bash\nnox -e format\n```\n# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [0.1.0-alpha.1]\n\n### Added\n\n-   Source code with the implementation of `get_contents` and `get_content`\n-   [Examples](./examples)\n-   Documentation [(README.md)](./README.md)\n-   [GitHub Actions pipeline](https://github.com/getjoystick/joystick-python/tree/main/.github/workflows) to check code style + Unit Testing at different Python versions + different platforms\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Joystick is a modern remote configuration and dynamic content service designed specifically for operating apps and games. Upgrade to more agility and evolve your product faster. Change or hot-update your content and configurations instantly at scale without code. Segment, ab test, feature flag, schedule events and more. Joystick is a breeze to use yet powerful.",
    "version": "0.1.0a1",
    "split_keywords": [
        "remote configuration",
        "feature flagging",
        "dynamic content",
        "remote configs",
        "live-ops",
        "game ops",
        "ab testing",
        "segmentation",
        "dynamic json",
        "update json",
        "remote json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed05dfbf175d10abe8812c33c5b6a1583d71359074fa302d9d0dfdf5d029546f",
                "md5": "8c3a6e8c7fa8150669b4ec833f09b518",
                "sha256": "17755eb022e07a0e445e726a55caf5b735aa5cb0d0558c3015f7a5e9682cc1e1"
            },
            "downloads": -1,
            "filename": "joystick_python-0.1.0a1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8c3a6e8c7fa8150669b4ec833f09b518",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 16826,
            "upload_time": "2023-03-31T15:35:43",
            "upload_time_iso_8601": "2023-03-31T15:35:43.330243Z",
            "url": "https://files.pythonhosted.org/packages/ed/05/dfbf175d10abe8812c33c5b6a1583d71359074fa302d9d0dfdf5d029546f/joystick_python-0.1.0a1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "891621d430e810f5fdbe1eac1c1b67350c477667318e9ca7fee92e09ef46066e",
                "md5": "9d0e787da59c8687592b84ff3fc30ef9",
                "sha256": "cf64a5f51dfec88dc5ebd6d0ada5d4a19a6fdaa0faae3f82db48b131c3fa2642"
            },
            "downloads": -1,
            "filename": "joystick-python-0.1.0a1.tar.gz",
            "has_sig": false,
            "md5_digest": "9d0e787da59c8687592b84ff3fc30ef9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 17596,
            "upload_time": "2023-03-31T15:35:45",
            "upload_time_iso_8601": "2023-03-31T15:35:45.553847Z",
            "url": "https://files.pythonhosted.org/packages/89/16/21d430e810f5fdbe1eac1c1b67350c477667318e9ca7fee92e09ef46066e/joystick-python-0.1.0a1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-31 15:35:45",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "joystick-python"
}
        
Elapsed time: 1.01442s