Metadata-Version: 2.1
Name: hs-formation
Version: 4.1.12
Summary: A generic functional middleware infrastructure for Python.
Home-page: https://github.com/HiredScorelabs/hs-formation
License: MIT
Keywords: flask,django,requests,middleware,functional
Author: Dotan Nahum
Author-email: jondotan@gmail.com
Requires-Python: >=3.6.1
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Provides-Extra: lint
Requires-Dist: attrs (>=19.1,<20.0)
Requires-Dist: attrs-serde (>=0.2.2,<0.3.0)
Requires-Dist: cytoolz (>=0.9.0,<0.10.0)
Requires-Dist: lxml (>=4.2,<5.0)
Requires-Dist: pybreaker (>=0.4.5,<0.5.0)
Requires-Dist: requests (>=2.20,<3.0)
Requires-Dist: toolz (>=0.9.0,<0.10.0)
Requires-Dist: xmltodict (>=0.11.0,<0.12.0)
Project-URL: Documentation, https://github.com/jondot/formation
Project-URL: Repository, https://github.com/HiredScorelabs/hs-formation
Description-Content-Type: text/markdown

<!-- ![](media/cover.png) -->

# Formation
<!-- [![Build Status](https://travis-ci.org/jondot/formation.svg?branch=master)](https://travis-ci.org/jondot/formation.svg)
[![Coverage Status](https://coveralls.io/repos/github/jondot/formation/badge.svg?branch=master)](https://coveralls.io/github/jondot/formation?branch=master) -->

A generic functional middleware infrastructure for Python.

Take a look:

```py
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 using pip/pipenv/etc. (we recommend [poetry](https://github.com/sdispater/poetry) for sane dependency management):

```
$ poetry add formation
```

## 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).






### Thanks:

To all [Contributors](https://github.com/jondot/formation/graphs/contributors) - you make this happen, thanks!

# Copyright

Copyright (c) 2018 [@jondot](http://twitter.com/jondot). See [LICENSE](LICENSE.txt) for further details.

