Formation
A generic functional middleware infrastructure for Python.
Take a look:
from datetime.datetime import now
from hs_formation import wrap
from requests import get
def log(ctx, call):
print("started")
ctx = call(ctx)
print("ended")
return ctx
def timeit(ctx, call):
started = now()
ctx = call(ctx)
ended = now() - started
ctx['duration'] = ended
return ctx
def to_requests(ctx):
get(ctx['url'])
return ctx
fancy_get = wrap(to_requests, middleware=[log, timeit])
fancy_get({'url':'https://google.com'})
Quick Start
Install from PyPI:
$ pip install hs-formation
Development
Install runtime dependencies plus the dev and ci groups, then run tests:
$ make install
$ make test
The ci group lists everything needed to execute the test suite and produce a coverage report in CI (for example pytest, pytest-cov, and other plugins). The dev group lists local-only tools such as pytest-watch.
To install only what CircleCI uses (no dev-only tools):
$ make install_ci
make ci_install is an alias for make install_ci.
After changing dependencies:
$ make lock
To verify pdm.lock is up to date without writing:
$ make verify_lock_file
Releases and tags
Release automation is handled by ci/release.sh and Makefile targets:
$ make release # patch
$ make release_minor # minor
$ make release_major # major
For breaking changes (for example dropping Python support), use a major release so the tag and package version move to the next major semver:
$ make release_major
Best Practices
A context object is a loose bag of objects. With that freedom comes responsibility and opinion.
For example, this is how Formation models a requests integration, with data flowing inside context:
- It models a
FormationHttpRequestwhich abstracts the essentials of making an HTTP request (later shipped torequestsitself in the way that it likes) - It tucks
FormationHttpRequestunder thefmtn.reqkey. - Additional information regarding such a request is kept alongside
fmtn.req. For example a request id is kept in thereq.idkey. This creates a flat (good thing) dict to probe. The reason additional data does not have thefmtnprefix is that you can always build your own that uses a different prefix (which you cant say about internal Formation inner workings).
added support for async http client via aio_http
You can use this via for_aio_http
Thanks:
To all Contributors - you make this happen, thanks!
Copyright
Copyright (c) 2018 @jondot. See LICENSE for further details.
Metadata
Release files for hs-formation 6.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 | Provenance | Actions |
|---|---|---|---|---|
| hs_formation-6.0.1.tar.gz | 345.0 kB | Without provenance | Details for hs_formation-6.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hs_formation-6.0.1-py3-none-any.whl | Python 3 | none | any | Details for hs_formation-6.0.1-py3-none-any.whl |
Total release size: 360.2 kB
Release files / hs_formation-6.0.1.tar.gz
| Download URL | hs_formation-6.0.1.tar.gz |
|---|---|
| Size | 345.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97a1ccf1cb30e4403dfc8f95fbb46b70fd2be08ea4afed70d9cbeb4187802381
|
|
BLAKE2b-256 checksum How to use checksums |
95abb5d5b87b632c5d4992dbbd169bb500878647ec3aca6d4f6a2c1cfcb4fdd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.9 CPython/3.9.16 Darwin/25.5.0
|
Release files / hs_formation-6.0.1-py3-none-any.whl
| Download URL | hs_formation-6.0.1-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e608b019c9c7b61821cbfb5c9ddf29291368240641871c5b977f3af25119f38
|
|
BLAKE2b-256 checksum How to use checksums |
b615f26a994c689eb195aa594589fa30b709e1eef368c2c7110a599967ef976b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.9 CPython/3.9.16 Darwin/25.5.0
|
Security for hs-formation 6.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.