Package: joystick-python
Pythong client forJoystickThis is the library that simplifies the way how you can communicate withJoystick API.InstallationYou can install the package viaPip:pipinstalljoystick-pythonUsageWe provide two types of clients: asynchronous and synchronous. They have exactly the same interfaces,
the only difference is a way you import them.Async / SyncSyncimportosfromjoystickimportClientjoystick_api_key=os.getenv("JOYSTICK_API_KEY")ifjoystick_api_keyisNone:raiseValueError("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"]}')AsyncimportasyncioimportosfromjoystickimportAsyncClientasyncdefmain():joystick_api_key=os.getenv("JOYSTICK_API_KEY")ifjoystick_api_keyisNone:raiseValueError("Please set JOYSTICK_API_KEY environment variable.")client=AsyncClient(api_key=joystick_api_key,)response=awaitclient.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 forasyncversion of the client. For sync it's enough to
use proper Client and avoidawaitkeywordRequesting content by single Content Id...awaitclient.get_content('cid1')...Specifying additional parameterWhen creating theClient/AsyncClientinstance, you can specify additional parameters which will
be used by all API calls from the client, for more details seeAPI 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",)Optionsfull_responseIn most of the cases you will be not interested in the full response from the API, but if you're you can specifyfullResponseoption to the client methods. The client will return you raw API response:get_content_response=awaitclient.get_content('cid1',full_response=True)# ORget_contents_response=awaitclient.get_contents({'cid1'},full_response=True)serializedWhentrue, we will pass query parameterresponseType=serializedtoJoystick API.get_content_response=awaitclient.get_content('cid1',serialized=True)# ORget_contents_response=awaitclient.get_contents({'cid1'},serialized=True)This option can be set for every API call from the client by settingserializedastruevia
constructor, or via propert setter.client=AsyncClient(api_key=joystick_api_key,serialized=True,)refreshIf you want to ignore existing cache and request the new config – pass this option astrue.get_content_response=awaitclient.get_content('cid1',refresh=True)# ORget_contents_response=awaitclient.get_contents({'cid1'},refresh=True)CachingBy default, the client usesin-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 eitherAsyncCacheInterfaceif you useAsyncClient,
orSyncCacheInterfaceif you useSyncClient.Async supportWe rely on libraryhttpxto make requests to Joystick API and we
support thesame platforms ashttpx.Clear the cacheIf you want to clear the cache – runawait client.clear_cache().Library developmentWe use thepyenvto install multiple versions of Python on the developer's machine andvenvto create the virtual environment for these versions:pyenvglobal3.5.10
rm-rf./venv# This one might fail, if it's the first time you create `venv` in this proj.python3-mvenvvenvsource./venv/bin/activate
pipinstall-e'.[dev]'Run unit testsnox-etestVery code style and formatnox-eformatChangelogAll notable changes to this project will be documented in this file.The format is based onKeep a Changelog,
and this project adheres toSemantic Versioning.[0.1.0-alpha.1]AddedSource code with the implementation ofget_contentsandget_contentExamplesDocumentation(README.md)GitHub Actions pipelineto check code style + Unit Testing at different Python versions + different platforms