The PolyAPI Python Library lets you use and define PolyAPI functions using Python.
First install the client.
We recommend the use of venv so you can have multiple projects each with separate credentials:
python -m venv myvenv
source myvenv/bin/activate
pip install polyapi-pythonReplace myvenv with whatever you'd like your venv to be named!
For more on Python virtual environments, we recommend this venv primer.
However, if you only need to use polyapi with a single project, you can do a basic install:
pip install polyapi-pythonNow you can run the following to generate your library
python -m polyapi generateYou will be prompted to enter the Poly server url you use and your Poly API key.
You can also provide the key and url as environment variables (useful for deployment):
POLY_API_KEY='your_key'
POLY_API_BASE_URL='your_server'  # e.g. na1.polyapi.io
That's it! Now open up a test file and you can run some code like so:
from polyapi import poly
print(poly.polyapi.function.api.list(my_server, my_api_key))To add a new server function, please follow the quickstart. Then you can add a server function like so:
python -m polyapi --context mycontext --description mydesc --server function add <function_name> foo.pyThe code in foo.py should contain a single defined function named the same as your <function_name> variable.
So for example, if you want to add a function named bar, your file foo.py would look like this:
def bar():
    return "Hello World"You can define arbitrarily complex argument and return types using TypedDicts.
NOTE: you must use TypedDict from typing_extensions, not from the base typing module.
from typing_extensions import TypedDict
class Foobar(TypedDict):
    count: int
def bar(n: int) -> Foobar:
    return Foobar(count=n)This library is hosted on Pypi. You can find the latest version on the pypi polyapi-python project.
To upgrade your library to the latest version, pass the upgrade flag.
pip install polyapi-python --upgradeTo upgrade your library to the latest dev version, pass the --pre flag.
pip install polyapi-python --pre --upgradeIf you need to change your API key or what server you are pointing to, you can run:
python -m polyapi setupTo run this library's unit tests, please clone the repo then run:
python -m unittest discoverIf you run into any issues or want help getting started with this project, please contact [email protected]