hs-formation


Namehs-formation JSON
Version 5.5.0 PyPI version JSON
download
home_pagehttps://github.com/HiredScorelabs/hs-formation
SummaryA generic functional middleware infrastructure for Python.
upload_time2023-10-19 07:53:34
maintainer
docs_urlNone
authorDotan Nahum
requires_python>=3.7
licenseMIT
keywords flask django requests middleware functional
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            <!-- ![](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).


### added support for async http client via aio_http
You can use this via ```for_aio_http```



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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/HiredScorelabs/hs-formation",
    "name": "hs-formation",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "flask,django,requests,middleware,functional",
    "author": "Dotan Nahum",
    "author_email": "jondotan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d6/fe/9dd968476c4abebff6c27a4e636d18ebfd7d8ec1b8635dded33a476c76fc/hs_formation-5.5.0.tar.gz",
    "platform": null,
    "description": "<!-- ![](media/cover.png) -->\n\n# Formation\n<!-- [![Build Status](https://travis-ci.org/jondot/formation.svg?branch=master)](https://travis-ci.org/jondot/formation.svg)\n[![Coverage Status](https://coveralls.io/repos/github/jondot/formation/badge.svg?branch=master)](https://coveralls.io/github/jondot/formation?branch=master) -->\n\nA generic functional middleware infrastructure for Python.\n\nTake a look:\n\n```py\nfrom datetime.datetime import now\nfrom hs_formation import wrap\nfrom requests import get\n\ndef log(ctx, call):\n    print(\"started\")\n    ctx = call(ctx)\n    print(\"ended\")\n    return ctx\n\ndef timeit(ctx, call):\n    started = now()\n    ctx = call(ctx)\n    ended = now() - started\n    ctx['duration'] = ended\n    return ctx\n\ndef to_requests(ctx):\n    get(ctx['url'])\n    return ctx\n\nfancy_get = wrap(to_requests, middleware=[log, timeit])\nfancy_get({'url':'https://google.com'})\n```\n\n## Quick Start\n\nInstall using pip/pipenv/etc. (we recommend [poetry](https://github.com/sdispater/poetry) for sane dependency management):\n\n```\n$ poetry add formation\n```\n\n## Best Practices\n\nA `context` object is a loose bag of objects. With that freedom comes responsibility and opinion.\n\nFor example, this is how Formation models a `requests` integration, with data flowing inside `context`:\n\n\n* It models a `FormationHttpRequest` which abstracts the essentials of making an HTTP request (later shipped to `requests` itself in the way that it likes)\n* It tucks `FormationHttpRequest` under the `fmtn.req` key.\n* 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).\n\n\n### added support for async http client via aio_http\nYou can use this via ```for_aio_http```\n\n\n\n### Thanks:\n\nTo all [Contributors](https://github.com/jondot/formation/graphs/contributors) - you make this happen, thanks!\n\n# Copyright\n\nCopyright (c) 2018 [@jondot](http://twitter.com/jondot). See [LICENSE](LICENSE.txt) for further details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A generic functional middleware infrastructure for Python.",
    "version": "5.5.0",
    "project_urls": {
        "Documentation": "https://github.com/jondot/formation",
        "Homepage": "https://github.com/HiredScorelabs/hs-formation",
        "Repository": "https://github.com/HiredScorelabs/hs-formation"
    },
    "split_keywords": [
        "flask",
        "django",
        "requests",
        "middleware",
        "functional"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "976e15849251f6d04fac6e9656ae4b0a9e540b275745095f6d13799b346c437d",
                "md5": "fc9aadaff50f32df940fe0d4ad729d77",
                "sha256": "a13dbf528a5b9e254173bb2e73b4d19dba4a7cf6aeb64bb76cce9ebe04e1a5e1"
            },
            "downloads": -1,
            "filename": "hs_formation-5.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fc9aadaff50f32df940fe0d4ad729d77",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 14680,
            "upload_time": "2023-10-19T07:53:32",
            "upload_time_iso_8601": "2023-10-19T07:53:32.733710Z",
            "url": "https://files.pythonhosted.org/packages/97/6e/15849251f6d04fac6e9656ae4b0a9e540b275745095f6d13799b346c437d/hs_formation-5.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d6fe9dd968476c4abebff6c27a4e636d18ebfd7d8ec1b8635dded33a476c76fc",
                "md5": "b4f797682458bb5b886c99719fee61d6",
                "sha256": "95e94ed1e2c82d9fcecfd7836b40ae374dff27f91793a7f5850632425133f9e0"
            },
            "downloads": -1,
            "filename": "hs_formation-5.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b4f797682458bb5b886c99719fee61d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10242,
            "upload_time": "2023-10-19T07:53:34",
            "upload_time_iso_8601": "2023-10-19T07:53:34.672374Z",
            "url": "https://files.pythonhosted.org/packages/d6/fe/9dd968476c4abebff6c27a4e636d18ebfd7d8ec1b8635dded33a476c76fc/hs_formation-5.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-19 07:53:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HiredScorelabs",
    "github_project": "hs-formation",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "hs-formation"
}
        
Elapsed time: 0.13023s