Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PolyAPI Python Library

The PolyAPI Python Library lets you use and define PolyAPI functions using Python.

PolyAPI Quickstart

1. Install Libraries

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-python

Replace 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-python

2. Generate Your Functions

Now you can run the following to generate your library

python -m polyapi generate

You 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

HTTP Client Configuration

The SDK reuses one synchronous HTTP client per process and one asynchronous client per event loop. New clients read these optional environment variables:

Variable Default Description
POLY_HTTP_MAX_CONNECTIONS 200 Maximum connections per client
POLY_HTTP_MAX_KEEPALIVE_CONNECTIONS none Maximum idle keep-alive connections per client
POLY_HTTP_KEEPALIVE_EXPIRY 30 Idle keep-alive expiry in seconds
POLY_HTTP_CONNECT_TIMEOUT none Connection timeout in seconds
POLY_HTTP_READ_TIMEOUT none Read timeout in seconds
POLY_HTTP_WRITE_TIMEOUT none Write timeout in seconds
POLY_HTTP_POOL_TIMEOUT none Connection-pool timeout in seconds
POLY_HTTP_CLOSE_TIMEOUT 5 Deadline in seconds for closing a client's pool

An empty value, none, or null means unbounded. Limits are per client, so processes with multiple event loops can create one configured pool per loop.

POLY_HTTP_CLOSE_TIMEOUT is read at shutdown rather than at client creation. It bounds pool teardown so a single unresponsive socket cannot stall shutdown: if the deadline passes, the SDK logs a warning, abandons the remaining connections to the operating system, and retires the client so it is never reused. Set it to none to wait indefinitely.

Call polyapi.http_client.close() during synchronous shutdown or await polyapi.http_client.close_async() on each owning event loop during asynchronous shutdown. The shutdown functions wait for active SDK requests before closing their client. Clients on standard asyncio loops are closed automatically when the loop closes. If a custom event-loop implementation reports that its close hook could not be installed, explicitly await close_async() before closing that loop.

3. Test

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))

Add New Server Functions

To add a new server function, please follow the quickstart. Then you can add a server function like so:

python -m polyapi function add <function_name> foo.py --server --context mycontext --description mydesc

The 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"

Complex Types In Server Functions

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)

Pypi

This library is hosted on Pypi. You can find the latest version on the pypi polyapi-python project.

Upgrade

To upgrade your library to the latest version, pass the upgrade flag.

pip install polyapi-python --upgrade

Pre-Release

To upgrade your library to the latest dev version, pass the --pre flag.

pip install polyapi-python --pre --upgrade

Change Your API Key

If you need to change your API key or what server you are pointing to, you can run:

python -m polyapi setup

Unit Tests

To run this library's unit tests, please clone the repo then run:

python -m unittest discover

Linting

The flake8 config is at the root of this repo at .flake8.

When hacking on this library, please enable flake8 and add this line to your flake8 args (e.g., in your VSCode Workspace Settings):

--config=.flake8

Mypy Type Improvements

This script is handy for checking for any mypy types:

./check_mypy.sh

Please ignore [name-defined] errors for now. This is a known bug we are working to fix!

Strategies for QA'ing Changes To Generate Or Other Core Functionality

Our https://na1.polyapi.io has a large OOB catalog (as does eu1/na2). We also have several big internal PolyAPI projects with Python (message @eupharis if you need a pointer to which ones).

Running python -m polyapi generate in all these projects and then checking the flake8 and check_mypy steps above is a great way to build confidence that the generate changes has no gotchas.

Of course all this is in addition to the changes passing through normal unittests and integration tests!

Support

If you run into any issues or want help getting started with this project, please contact support@polyapi.io .

Metadata

Release files for polyapi-python 0.3.21.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polyapi-python 0.3.21.dev0
File Size Uploaded
polyapi_python-0.3.21.dev0.tar.gz 95.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polyapi-python 0.3.21.dev0
File Interpreter ABI Platform
polyapi_python-0.3.21.dev0-py3-none-any.whl Python 3 none any Details

Total release size: 164.6 kB

Release files / polyapi_python-0.3.21.dev0.tar.gz

Download URL polyapi_python-0.3.21.dev0.tar.gz
Size 95.1 kB
Tags Source
SHA-256 checksum
How to use checksums
63be6fb689b3bd72d08f62f8a15c49468463d655ad6d48c95d0a0594036c0948
BLAKE2b-256 checksum
How to use checksums
8a31ae0e507b0142fbacc0929e84ce8bf1b9e9cc82d3866fbd742a186fae4a0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / polyapi_python-0.3.21.dev0-py3-none-any.whl

Download URL polyapi_python-0.3.21.dev0-py3-none-any.whl
Size 69.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28f2233a89467f220abb559c6b2e1acbdeac32ce9758648ec6bd11d606b3b248
BLAKE2b-256 checksum
How to use checksums
3d3e716d37cc9f964b9f93ca7f8e2cfb93ebfaaaf5d4642c83c683e97abe698a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.21.dev0 This release

2 release files

0.3.20

2 release files

0.3.19

2 release files

0.3.18

2 release files

0.3.15

2 release files

0.3.14

2 release files

0.3.13

2 release files

0.3.12

2 release files

0.3.11

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.4

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.35

2 release files

0.0.34

2 release files

0.0.33

2 release files

0.0.32

2 release files

0.0.31

2 release files

0.0.30

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.12

2 release files

0.0.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page