Skip to main content

pyfaaster

Build Status

Useful Utilities for Python Functions as a Service (starting with AWS Lambda).

Problem

Functions as a Service can be joyful. When paired with a concise language like Python, you start to rethink the need for a "web framework" like Rails, Django, etc: couple your functions with your FaaS provider's API Gateway and you are off an running with minimal code. Of course, there is still some boilerplate code around injecting environment, formatting responses, checking arguments, etc.

Concept

The goal of pyfaaster is to cut through the cruft and get you humming along with your Python FaaS. pyfaaster accomplishes this goal by providing you with useful middleware (i.e. decorators) for your lambda functions. Additionally, pyfaaster can be used for its excellent Makefile and serverless.yml examples.

Cheers!

Usage

The following is a non-exhaustive list and details of the useful middleware. More can be found in pyfaaster.aws.handler_decorators.

Environment Variables

You don't want to sprinkle os.environ throughout your code. Let us do that for you.

import pyfaaster as faas

@faas.environ_aware(['REQUIRED_ENV'], ['OPTIONAL_ENV'])
def handler(event, context, REQUIRED_ENV=None, OPTIONAL_ENV=None):
    assert REQUIRED_ENV == os.environ['REQUIRED_ENV']     # <- faas.environ_aware will return early with a useful message if this is not set
    assert OPTIONAL_ENV == os.environ.get('OPTIONAL_ENV')

Configuration Files

Similarly, don't worry about injecting those S3 Configuration files.

import pyfaaster as faas

@faas.configuration_aware('config.json', True)   # S3 key to a config file, create if not there
def handler(event, context, configuration=None):
    assert configuration == < { 
    'load': lambda : {contents of config bucket},
    'save': lambda d : save d into config bucket,
    }

Response Format

Sigh, you have to manually convert your lambda return values to API Gateway's expected dictionary? Don't forget to serialize all your json into the body element! Oh wait ... just use

import pyfaaster as faas

@faas.http_response(default_error_message='Failed to handle something.")
def handler(event, context, **kwargs):
    return { 'my': 'important', 'json': 'data'} # <- will end up as the json serialized `body` in an API Gateway compatible dict with statusCode.

Authorization

You gotta confirm your token scopes, friend!

import pyfaaster as faas

# Checks the event.requestContext.authorizer for the given scopes. This works nicely with AWS custom
# authorizers. An example one is coming to this library soon.

@faas.scopes('read:profile', 'update:email')
def handler(event, context, **kwargs):
    return 'Hello, Secure World!'

Release files for pyfaaster 0.2.4

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

Source distribution (sdist)

Source distribution for pyfaaster 0.2.4
File Size Uploaded
pyfaaster-0.2.4.tar.gz 14.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfaaster 0.2.4
File Interpreter ABI Platform
pyfaaster-0.2.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 34.6 kB

Release files / pyfaaster-0.2.4.tar.gz

Download URL pyfaaster-0.2.4.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0fc32bc01b58116c5e40bf1998f4ed6da504d17e0b260b8308e77d5af67ead1a
BLAKE2b-256 checksum
How to use checksums
1dbd2c6830cf3f5914510e49cc201ee5c11e540d3b751a10e94cc5fc7424eee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.8

Release files / pyfaaster-0.2.4-py2.py3-none-any.whl

Download URL pyfaaster-0.2.4-py2.py3-none-any.whl
Size 19.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
53d73c42433eded63947c8f29792d3fa4401ad4abfd82447f53c731f7502d8b2
BLAKE2b-256 checksum
How to use checksums
ad926566bfb5e4b31a29c15a7f5b9d4cd25334e11d39bca5938d8478e3331bd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.8

Release history Release notifications | RSS feed

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.2.6

3 release files

0.2.5

2 release files

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.15

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

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

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