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"

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 .

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.3.19.dev1.tar.gz (77.9 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.3.19.dev1-py3-none-any.whl (63.6 kB view details)

Uploaded Python 3

File details

Details for the file polyapi_python-0.3.19.dev1.tar.gz.

File metadata

  • Download URL: polyapi_python-0.3.19.dev1.tar.gz
  • Upload date:
  • Size: 77.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polyapi_python-0.3.19.dev1.tar.gz
Algorithm Hash digest
SHA256 17cbe51000aee8f3af6d02b63c3c43bada33ab3a067ab1ae8f748202b4ed2ffc
MD5 7c9bce8fcb2e0231cc0a9eabd21101bc
BLAKE2b-256 12e02d32896cb746f9c9f36ae5429ff5737a99561db825db32c5e7ffac8b1dfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyapi_python-0.3.19.dev1.tar.gz:

Publisher: polyapi-update-python-package.yml on polyapi/polyapi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polyapi_python-0.3.19.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for polyapi_python-0.3.19.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 30d22fdd29a3971c84a9507b542f60be80cb13b7c9f039d9219ff494625ba52e
MD5 807ed12a7868ad9f28a14559d9d94e4f
BLAKE2b-256 a5133e9a9d30fbc4990360707562670413c809a143c5ca42da750c0f7818f17f

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyapi_python-0.3.19.dev1-py3-none-any.whl:

Publisher: polyapi-update-python-package.yml on polyapi/polyapi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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