Skip to main content

Effortless serverless Python

Project description

๐Ÿ”ช Pare

version license python ci pyright ruff

Pare is the easiest way to deploy Python Lambdas alongside your primary web application.

Discord

pare_demo

Why use Pare?

Pare is built to allow web developers to independently scale parts of a web application. More specifically, Pare is useful if you have functions which are:

  • compute intensive
  • blocking
  • isolated
  • parallel

Some examples are document parsing, data aggregation, webhook handling and image processing.

With Pare, you can offload these tasks from your main web server, while also getting automatic scaling for concurrent requests.

Quickstart

First, mark the function you want to deploy onto a Lambda:

import pare

@pare.endpoint(name="quickstart")
def my_function(*args, **kwargs):
    ...

This will tell Pare to use this function as the Lambda handler.

Calling the function in your code will still execute locally, but the decorator adds additional methods to make calls to the deployed Lambda.

from my_module import my_function

my_function(*args, **kwargs)  # local function call

my_function.invoke(*args, **kwargs)  # remote Lambda call

await my_function.invoke_async(*args, **kwargs)  # async remote Lambda call

Next, login with Github to get a Pare API Key:

> pare login
Please visit: https://github.com/login/device
and enter code: 1111-1111

Following the on-screen instructions will authorize Gauge to retrieve your Github username and email for the purposes of account creation. The token has no other permissions.

After logging in, you can run a deploy of your function into the Pare Cloud:

> pare deploy my_module.py

[!NOTE] This generally takes between 3s (when heavily cached) and 60s (no cache, heavy dependencies)

Once the deploy is finished, you can verify with pare status:

> pare status
                      Deployment Data                      
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Name                   โ”ƒ Git Hash โ”ƒ Created At          โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ quickstart             โ”‚ 8a4096b  โ”‚ 2024-08-19 22:55:51 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

That's it! Your function is now serverless.

To delete a deployed function, use pare delete:

> pare delete quickstart --git-hash 8a4096b

Notes on Deployment

The pare deploy command accepts a sequence of file patterns (filepaths, directories, or glob paths). The corresponding files will be collected into a single bundle, which will be built and deployed with each function.

The entrypoint for each function will be defined by pare.endpoint, and it is critical that all of the entrypoint's imports are included in the bundle.

Third party dependencies are bundled with each function individually, see the section below for more details.

In the future, we plan to use the technology behind [Tach] to automatically determine the transitive dependencies in your project and create a complete bundle. Reach out on Discord if this is an important feature for you!

Advanced Usage

3rd Party Dependencies

Pare allows installing 3rd party dependencies from PyPI for each deployed function.

Use the dependencies kwarg in the endpoint decorator to specify the dependencies for a function, and they will automatically be installed during the deploy.

@pare.endpoint(name="3rd-party-deps", dependencies=["pydantic", ...])

The dependency names can specify version numbers as well, just as if they were listed in requirements.txt.

@pare.endpoint(name="3rd-party-deps", dependencies=["pydantic==2.8.2", ...])

[!TIP] If you want to quickly determine the 3rd party dependencies used by a set of files, consider using Tach with tach report-external

Environment Variables

Pare allows setting environment variables for your functions during the deploy.

Use the -e option to set environment variables:

> pare deploy my_module.py -e MY_VARIABLE=myvalue -e OTHER_VARIABLE=othervalue [...]

Atomic Deployment

Pare supports 'atomic deployment' of services based on a git hash.

When atomic deployment is disabled (the default), the Pare API will route requests by name to the latest deployed version of your function.

When atomic deployment is enabled, the Pare SDK will include the git hash in its requests to your deployed functions, and the Pare API will route your request to the service with a matching git hash.

This feature is enabled on the client-side with the environment variable PARE_ATOMIC_DEPLOYMENT_ENABLED.

Since your main application likely will not have access to git to determine its git hash at runtime, you will need to set the PARE_GIT_HASH environment variable during your build and deployment pipeline.

Project details


Download files

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

Source Distribution

pare-0.3.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

pare-0.3.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file pare-0.3.0.tar.gz.

File metadata

  • Download URL: pare-0.3.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pare-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5de6df0bbc8418e2da3e482869546b7fab7af4d6016d5a6fc06579c048a7a976
MD5 509efbee4e354ea87f284b4d9749a583
BLAKE2b-256 0238e381e8d6e61020a957315108ab1c723dd4a3537579a6970ad5779c6e40ec

See more details on using hashes here.

File details

Details for the file pare-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pare-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pare-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f72692c2edb4ea31d5a13f5fddf785f6159a02bd6a95ce2054105e89a8a82c8
MD5 cb03e595e80d13f5774ce0712a80463e
BLAKE2b-256 2525114a8c56f8937ca60e0090cf4405ccec8628e0d2fd6f5611c8910fedd771

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