Skip to main content

The Python Client for PolyAPI, the IPaaS by Developers for Developers

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"

See Server Function Logs

In order to see function logs, please first set logsEnabled to true in Canopy for the function.

https://na1.polyapi.io/canopy/polyui/collections/server-functions

Then in your code, get the poly logger and log with it like so:

logger = logging.getLogger("poly")
def bar():
    logger.warning("I AM THE LOG")
    return "Hello World"

Finally, click the "Show Logs" button to see your server function logs in Canopy!

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

Support

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

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.2.9.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

polyapi_python-0.2.9-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file polyapi_python-0.2.9.tar.gz.

File metadata

  • Download URL: polyapi_python-0.2.9.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for polyapi_python-0.2.9.tar.gz
Algorithm Hash digest
SHA256 89d8e067456f61d4392a29618100334ce1b890a66fcb88a4897c04e9ab9eb36a
MD5 10646460f77b398ea1e85ced4273ac18
BLAKE2b-256 a77989ffbf435c05c4a5ac9bd278dcccb22374fae14855dc4a75183569ddcdef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polyapi_python-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4cc9df01176504f4441b951191766feda50972e5a9b3bc1b9c14dcde1157009e
MD5 bc187de24ff5c88ae07f8a057167e4cc
BLAKE2b-256 a851b4480942831e8f5e8fb1d98140d76d516e14489f369b9e5f50f356c4fc70

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