Skip to main content

purus

Pytest codecov Code style: black Imports: isort Checked with mypy

PythonVersion PiPY

purus parses parameters provided from Lambda@Edge on CloudFront, and it manipulates request and response. It is named after The Purus River, or a tributary of The Amazon River.

Install

$ pip install purus

Usage

CloudFront:Lambda@Edge

purus can parse parameters of

  • viewer-request
  • origin-request
  • origin-response
  • viewer-response
# Lambda@Edge
from purus.amazon_cloudfront import CloudFrontLambdaEdge

# on viewer-request or origin-request
def lambda_handler(event: dict, _):
    # load data
    lambda_edge = CloudFrontLambdaEdge.from_event(event=event)
    
    # return on error
    if some_error_occurred:
        pseudo_payload = lambda_edge.add_pseudo_response(
            status="400",
            status_description="error_occurred"
        )
        return pseudo_payload.response.format()
    
    # redirect
    if redirect_condition:
        pseudo_payload = lambda_edge.add_pseudo_redirect_response(
            status="307",
            status_description="Redirect",
            location_url="https://redirect.example.com"
        )
        return pseudo_payload.response.format()
    
    # add headers to request
    modified_request = lambda_edge.append_request_header(
        key="X-Original-Header",
        value="Your data"
    ).append_request_header(
        key="X-Original-Header",
        value="Your additional data"
    )
    
    # to request
    return  modified_request.request.format()

Metadata

Release files for purus 0.1.1

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

Source distribution (sdist)

Source distribution for purus 0.1.1
File Size Uploaded
purus-0.1.1.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for purus 0.1.1
File Interpreter ABI Platform
purus-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / purus-0.1.1.tar.gz

Download URL purus-0.1.1.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2f15124f1b104b5d93a1e0ef0ac4fdf64481eec5c05a8828ff794b35f85e535b
BLAKE2b-256 checksum
How to use checksums
6fec8650aa9566afe6a9bd189ce61df4be06b7ba29edd52e6955e97c6a9bf18e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0 CPython/3.8.13 Linux/5.15.0-1019-azure

Release files / purus-0.1.1-py3-none-any.whl

Download URL purus-0.1.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f57295ddfe4fd7c44694c61f7e590f21665bc01a5610bf43841b78f8c1935279
BLAKE2b-256 checksum
How to use checksums
298ddbfd75bd414d47b645a407fb1b56be187f8b0eb8db3cd971055028e6794f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0 CPython/3.8.13 Linux/5.15.0-1019-azure

Release history Release notifications | RSS feed

This release

0.1.1 This release

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