late-python
A Python package with OpenStax Lambda@Edge ("lAMBDA at eDGE") utilities.
Overview
late-python provides object overlays
to the JSON containers
inside Lambda@Edge events and responses.
These overlay objects handle the details
of accessing and modifying
the containers they overlay.
All get_* methods
leave the underlying container intact,
and all set_* methods
modify it in place.
Usage
Dealing With Request Events
from oxlate import Event, Response
def lambda_handler(event, context):
request = Event(event).request() ## returns Request overlay
## get and set the request uri field
request.get_uri()
request.set_uri('/some/new/uri')
## get the viewer's country code
request.get_viewer_country()
## return Headers overlay
headers = request.get_headers()
## get the Request event header array-of-hash (or None if missing):
## [{name=..., value=...}]
headers.get(name='header-name')
## get the header value only
## (or None if missing and no default given)
headers.get_value(name='header-name', default='some default')
## set or overwrite a header
headers.set(
name = 'header-name',
value = 'some value',
)
## get a request cookie value
## (or None if missing and no default given)
headers.get_request_cookie('cookie_name', default='some default')
## set or overwrite a request cookie value
headers.set_request_cookie('cookie_name', value='some value')
## return a deep copy of the overlaid hashmap
return request.to_dict()
Dealing With Response Objects
from oxlate import Response
def request_handler(event, context):
## construct a Response object
response = Response(
status=302,
content_type='text/plain',
body=None,
)
## use method chaining to tweak Response
response.set_status(404) \
.set_content_type('custom/type') \
.set_content_type_json() \
.set_content_type_html() \
.set_body(json.dumps('some body text'))
## get a Headers overlay
headers = response.get_headers()
## get the header value only
## (or None if missing and no default given)
headers.get_value(name='header-name', default='some default')
## set or overwrite a header
headers.set(
name = 'header-name',
value = 'some value',
)
## get a ResponseCookie overlay
cookie = headers.get_response_cookie('cookie-name')
print(cookie.name())
print(cookie.value())
print(cookie.expires_at())
print(cookie.path())
print(cookie.domain())
## set or override a ResponseCookie
cookie = ResponseCookie(
name = 'cookie-name',
value = 'some value',
expires_at = datetime.datetime.utcnow() + datetime.timedelta(days=2),
path = '/',
domain = 'my.domain.com',
)
headers.set_response_cookie(cookie)
return response.to_dict()
Development
All development is done inside a docker container. From your host running Docker, in this directory run:
$> docker-compose up -d
%> ./docker/bash
This will drop you into the running container
Run tests
From within the container, you can run tests with:
$ /code> python -m pytest
For debugging, you can use ipdb, e.g.
import ipdb; ipdb.set_trace()
When running tests with the debugger make sure to use the -s option to prevent pytest from capturing output.
$> python -m pytest -s tests -k 'test_decrypts'
Note that pytest is also on the PATH so you can call it directly.
Distributing
...
Metadata
Release files for oxlate 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| oxlate-0.0.1.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| oxlate-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.5 kB
Release files / oxlate-0.0.1.tar.gz
| Download URL | oxlate-0.0.1.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f3668c533cc3a465d70497cf9a574825d74a3b5ff9f1389ef2c3eed2aedd62b
|
|
BLAKE2b-256 checksum How to use checksums |
f8aba55c3f8e21d94bc56bd12028d07ff2f3ea479095aacb34efd3d7266852e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.7
|
Release files / oxlate-0.0.1-py3-none-any.whl
| Download URL | oxlate-0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e79dda16cfa99eff87d843933990de43a6e7f0480e506296aea3edf331b61c9
|
|
BLAKE2b-256 checksum How to use checksums |
c6145a73ead92ea6ad779a70cbc14b6edd83ff99419b4d3089a32e31ff0b8f15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.7
|