{"id":13486499,"url":"https://github.com/jondot/formation","last_synced_at":"2025-03-21T01:31:54.592Z","repository":{"id":33750919,"uuid":"160396017","full_name":"jondot/formation","owner":"jondot","description":"A generic functional middleware infrastructure for Python.","archived":false,"fork":false,"pushed_at":"2023-01-26T09:32:00.000Z","size":2318,"stargazers_count":17,"open_issues_count":18,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-16T16:05:26.031Z","etag":null,"topics":["http","python","requests"],"latest_commit_sha":null,"homepage":"https://jondot.github.io/formation/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jondot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-04T17:41:11.000Z","updated_at":"2024-06-27T16:26:17.000Z","dependencies_parsed_at":"2023-02-14T15:45:31.073Z","dependency_job_id":null,"html_url":"https://github.com/jondot/formation","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jondot%2Fformation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jondot%2Fformation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jondot%2Fformation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jondot%2Fformation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jondot","download_url":"https://codeload.github.com/jondot/formation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244721271,"owners_count":20498922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","python","requests"],"created_at":"2024-07-31T18:00:47.263Z","updated_at":"2025-03-21T01:31:54.280Z","avatar_url":"https://github.com/jondot.png","language":"Python","readme":"![](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 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\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","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjondot%2Fformation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjondot%2Fformation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjondot%2Fformation/lists"}