Skip to main content

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.

Project description

Pythong client for Joystick

GitHub Actions Latest Stable Version PyPI Wheel Supported versions Supported implementations License

This is the library that simplifies the way how you can communicate with Joystick API.

Installation

You can install the package via Pip:

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

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

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

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

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:

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.

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.

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.

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, 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 if you use AsyncClient, or SyncCacheInterface if you use SyncClient.

Async support

We rely on library httpx to make requests to Joystick API and we support the same platforms as httpx.

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:

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

nox -e test

Very code style and format

nox -e format

Changelog

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

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.1.0-alpha.1]

Added

  • Source code with the implementation of get_contents and get_content
  • Examples
  • Documentation (README.md)
  • GitHub Actions pipeline to check code style + Unit Testing at different Python versions + different platforms

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

joystick-python-0.1.0a1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

joystick_python-0.1.0a1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file joystick-python-0.1.0a1.tar.gz.

File metadata

  • Download URL: joystick-python-0.1.0a1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for joystick-python-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 cf64a5f51dfec88dc5ebd6d0ada5d4a19a6fdaa0faae3f82db48b131c3fa2642
MD5 9d0e787da59c8687592b84ff3fc30ef9
BLAKE2b-256 891621d430e810f5fdbe1eac1c1b67350c477667318e9ca7fee92e09ef46066e

See more details on using hashes here.

File details

Details for the file joystick_python-0.1.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for joystick_python-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 17755eb022e07a0e445e726a55caf5b735aa5cb0d0558c3015f7a5e9682cc1e1
MD5 8c3a6e8c7fa8150669b4ec833f09b518
BLAKE2b-256 ed05dfbf175d10abe8812c33c5b6a1583d71359074fa302d9d0dfdf5d029546f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page