# pyfaaster
[](https://semaphoreci.com/cloudzero/pyfaaster)
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](https://github.com/Cloudzero/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.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyfaaster-0.1.15.tar.gz | 12.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyfaaster-0.1.15-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 30.9 kB
Release files / pyfaaster-0.1.15.tar.gz
| Download URL | pyfaaster-0.1.15.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23245164c6282a6d1a0bfa7e2d10d9ceaed7af1c7da37b8b40c587ea69b7ee0c
|
|
BLAKE2b-256 checksum How to use checksums |
6713bd611e59b60474842c1ae2c06277bcf4ae7f930c41f8903eecd36d0b1a8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pyfaaster-0.1.15-py2.py3-none-any.whl
| Download URL | pyfaaster-0.1.15-py2.py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
8b90f349c6d4dc9e5b5f5bd660a5a550e303973869ddccc4e46b478c64ee2806
|
|
BLAKE2b-256 checksum How to use checksums |
c09806fb2517e65b02adb7fe551bcb58fc8d448170dfa903f6cca42a04c7409a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |