Skip to main content

The PolyAPI Python Client

Project description

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

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 --context mycontext --description mydesc --server function add <function_name> foo.py

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 myfunc(n: int) -> Foobar:
    return Foobar(count=n)

Upgrade

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

pip install polyapi-python --upgrade

Unit Tests

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

python -m unittest discover

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

polyapi-python-0.0.21.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polyapi_python-0.0.21-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file polyapi-python-0.0.21.tar.gz.

File metadata

  • Download URL: polyapi-python-0.0.21.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for polyapi-python-0.0.21.tar.gz
Algorithm Hash digest
SHA256 6343ab81deedb6dd1fdf57d96f164faef3bbc9f1f26d39159e89c23a4c28ab79
MD5 579e553333845d1a32199071d644048d
BLAKE2b-256 44a094d892926aed1c72c3188b862e7e33beeff54727803b24a88eb44c8e724a

See more details on using hashes here.

File details

Details for the file polyapi_python-0.0.21-py3-none-any.whl.

File metadata

File hashes

Hashes for polyapi_python-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 9894fdeb3ddfb9ae08c79354d0c6fe8624855a7bdb59589a4f30f0970da6364e
MD5 b54d7aacfb9d5bbbd5c3fae976a887d6
BLAKE2b-256 809350a53129ebaa3c17fdf973bf7802b662452098c416ac5a5c9e16cc0a6caf

See more details on using hashes here.

Supported by

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