Skip to main content

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 FormationHttpRequest which abstracts the essentials of making an HTTP request (later shipped to requests itself in the way that it likes)
  • It tucks FormationHttpRequest under the fmtn.req key.
  • Additional information regarding such a request is kept alongside fmtn.req. For example a request id is kept in the req.id key. This creates a flat (good thing) dict to probe. The reason additional data does not have the fmtn prefix 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hs_formation-6.0.1.tar.gz (345.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hs_formation-6.0.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file hs_formation-6.0.1.tar.gz.

File metadata

  • Download URL: hs_formation-6.0.1.tar.gz
  • Upload date:
  • Size: 345.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.9 CPython/3.9.16 Darwin/25.5.0

File hashes

Hashes for hs_formation-6.0.1.tar.gz
Algorithm Hash digest
SHA256 97a1ccf1cb30e4403dfc8f95fbb46b70fd2be08ea4afed70d9cbeb4187802381
MD5 14f61659c634ec971d5f7670aacb36ff
BLAKE2b-256 95abb5d5b87b632c5d4992dbbd169bb500878647ec3aca6d4f6a2c1cfcb4fdd1

See more details on using hashes here.

File details

Details for the file hs_formation-6.0.1-py3-none-any.whl.

File metadata

  • Download URL: hs_formation-6.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.9 CPython/3.9.16 Darwin/25.5.0

File hashes

Hashes for hs_formation-6.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e608b019c9c7b61821cbfb5c9ddf29291368240641871c5b977f3af25119f38
MD5 5777a2ec3fbdcffffae72647f5fbbddb
BLAKE2b-256 b615f26a994c689eb195aa594589fa30b709e1eef368c2c7110a599967ef976b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

6.0.1 This release

2 files

5.5.0

2 files

5.4.0

2 files

5.2.0

2 files

5.1.0

2 files

5.0.2

2 files

5.0.0

2 files

4.3.7

2 files

4.3.6

2 files

4.3.5

2 files

4.3.4

2 files

4.3.1

2 files

4.3.0

2 files

4.2.2

2 files

4.2.1

2 files

4.1.13

2 files

4.1.12

2 files

4.1.11

2 files

4.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page