{"id":33196614,"url":"https://github.com/mentalisttraceur/python-compose","last_synced_at":"2025-12-15T23:50:54.246Z","repository":{"id":37376813,"uuid":"225898996","full_name":"mentalisttraceur/python-compose","owner":"mentalisttraceur","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-27T20:34:55.000Z","size":68,"stargazers_count":33,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-21T02:03:50.466Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mentalisttraceur.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-12-04T15:30:36.000Z","updated_at":"2024-11-06T23:45:26.000Z","dependencies_parsed_at":"2024-04-23T23:08:29.890Z","dependency_job_id":"190e0b6e-7dd7-466f-84d2-5ac7c854d258","html_url":"https://github.com/mentalisttraceur/python-compose","commit_stats":{"total_commits":120,"total_committers":1,"mean_commits":120.0,"dds":0.0,"last_synced_commit":"126c5c31fd1b1e2c37c3c9612c04a21890c96f64"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/mentalisttraceur/python-compose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mentalisttraceur%2Fpython-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mentalisttraceur%2Fpython-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mentalisttraceur%2Fpython-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mentalisttraceur%2Fpython-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mentalisttraceur","download_url":"https://codeload.github.com/mentalisttraceur/python-compose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mentalisttraceur%2Fpython-compose/sbom","scorecard":{"id":636609,"data":{"date":"2025-08-11","repo":{"name":"github.com/mentalisttraceur/python-compose","commit":"685849cf10f97bfbb6def9d02cc380d5dd9923a9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD Zero Clause License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-21T09:21:59.053Z","repository_id":37376813,"created_at":"2025-08-21T09:21:59.053Z","updated_at":"2025-08-21T09:21:59.053Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27757826,"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","status":"online","status_checked_at":"2025-12-15T02:00:09.782Z","response_time":96,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-11-16T08:00:27.636Z","updated_at":"2025-12-15T23:50:54.220Z","avatar_url":"https://github.com/mentalisttraceur.png","language":"Python","readme":"compose\n=======\n\nThe classic ``compose``, with all the Pythonic features.\n\nThis ``compose`` follows the lead of ``functools.partial``\nand returns callable ``compose`` objects which:\n\n* have a regular and unambiguous ``repr``,\n* retain correct signature introspection,\n* allow introspection of the composed callables,\n* can be type-checked,\n* can be weakly referenced,\n* can have attributes,\n* will merge when nested, and\n* can be pickled (if all composed callables can be pickled).\n\nFor ``async``/``await`` support, different variants of\n``compose`` are included.\n\n\nVersioning\n----------\n\nThis library's version numbers follow the `SemVer 2.0.0\nspecification \u003chttps://semver.org/spec/v2.0.0.html\u003e`_.\n\n\nInstallation\n------------\n\n::\n\n    pip install compose\n\nFor static type checking, also install `the type hint\nstubs \u003chttps://pypi.org/project/compose-stubs\u003e`_:\n\n::\n\n    pip install compose-stubs\n\n\nUsage\n-----\n\nBasics\n~~~~~~\n\nImport ``compose``:\n\n.. code:: python\n\n    \u003e\u003e\u003e from compose import compose\n\nAll the usual function composition you know and love:\n\n.. code:: python\n\n    \u003e\u003e\u003e def double(x):\n    ...     return x * 2\n    ...\n    \u003e\u003e\u003e def increment(x):\n    ...     return x + 1\n    ...\n    \u003e\u003e\u003e double_then_increment = compose(increment, double)\n    \u003e\u003e\u003e double_then_increment(1)\n    3\n\nOf course any number of functions can be composed:\n\n.. code:: python\n\n    \u003e\u003e\u003e def double(x):\n    ...     return x * 2\n    ...\n    \u003e\u003e\u003e times_eight = compose(double, double, double)\n    \u003e\u003e\u003e times_16 = compose(double, double, double, double)\n\nWe still get the correct signature introspection:\n\n.. code:: python\n\n    \u003e\u003e\u003e def f(a, b, c=0, **kwargs):\n    ...     pass\n    ...\n    \u003e\u003e\u003e def g(x):\n    ...     pass\n    ...\n    \u003e\u003e\u003e g_of_f = compose(g, f)\n    \u003e\u003e\u003e import inspect\n    \u003e\u003e\u003e inspect.signature(g_of_f)\n    \u003cSignature (a, b, c=0, **kwargs)\u003e\n\nAnd we can inspect all the composed callables:\n\n.. code:: python\n\n    \u003e\u003e\u003e g_of_f.functions  # in order of execution:\n    (\u003cfunction f at 0x...\u003e, \u003cfunction g at 0x...\u003e)\n\n``compose`` instances flatten when nested:\n\n.. code:: python\n\n   \u003e\u003e\u003e times_eight_times_two = compose(double, times_eight)\n   \u003e\u003e\u003e times_eight_times_two.functions == times_16.functions\n   True\n\nWhen programmatically inspecting arbitrary callables, we\ncan check if we are looking at a ``compose`` instance:\n\n.. code:: python\n\n    \u003e\u003e\u003e isinstance(g_of_f, compose)\n    True\n\n``compose`` raises a ``TypeError`` when called with\nno arguments or with any non-callable arguments:\n\n.. code:: python\n\n    \u003e\u003e\u003e compose()\n    Traceback (most recent call last):\n        ...\n    TypeError: compose() needs at least one argument\n\n.. code:: python\n\n    \u003e\u003e\u003e compose(increment, 'oops', increment)\n    Traceback (most recent call last):\n        ...\n    TypeError: compose() arguments must be callable\n\n\n``async``/``await``\n~~~~~~~~~~~~~~~~~~~\n\nWe can compose ``async`` code by using ``acompose``:\n\n.. code:: python\n\n    \u003e\u003e\u003e import asyncio\n    \u003e\u003e\u003e from compose import acompose\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e async def get_data():\n    ...     # pretend this data is fetched from some async API\n    ...     await asyncio.sleep(0)\n    ...     return 42\n    ...\n    \u003e\u003e\u003e get_and_double_data = acompose(double, get_data)\n    \u003e\u003e\u003e asyncio.run(get_and_double_data())\n    84\n\n``acompose`` can compose any number of ``async``\nand regular functions, in any order:\n\n.. code:: python\n\n    \u003e\u003e\u003e async def async_double(x):\n    ...     await asyncio.sleep(0)\n    ...     return x * 2\n    ...\n    \u003e\u003e\u003e async_times_16 = acompose(async_double, double, async_double, double)\n    \u003e\u003e\u003e asyncio.run(async_times_16(1))\n    16\n\n``acompose`` instances always return awaitable values,\neven if none of the composed functions are ``async``:\n\n.. code:: python\n\n    \u003e\u003e\u003e awaitable_times_16 = acompose(double, double, double, double)\n    \u003e\u003e\u003e asyncio.run(awaitable_times_16(1))\n    16\n\n``sacompose`` is like ``acompose``, but ``sacompose``\ninstances return an awaitable value only if any of\nthe composed functions return an awaitable value:\n\n.. code:: python\n\n    \u003e\u003e\u003e from compose import sacompose\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e regular_times_4 = sacompose(double, double)\n    \u003e\u003e\u003e async_times_4 = sacompose(double, async_double)\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e regular_times_4(1)\n    4\n    \u003e\u003e\u003e asyncio.run(async_times_4(1))\n    4\n\nIf |markcoroutinefunction|_ is available,\n``acompose`` and ``sacompose`` instances\nwill be correctly detected as coroutine functions:\n\n.. |markcoroutinefunction| replace:: ``inspect.markcoroutinefunction``\n.. _markcoroutinefunction:  https://docs.python.org/3/library/inspect.html#inspect.markcoroutinefunction\n\n.. code:: python\n\n    \u003e\u003e\u003e inspect.iscoroutinefunction(async_times_16)\n    True\n    \u003e\u003e\u003e inspect.iscoroutinefunction(awaitable_times_16)\n    True\n    \u003e\u003e\u003e inspect.iscoroutinefunction(regular_times_4)\n    False\n    \u003e\u003e\u003e inspect.iscoroutinefunction(async_times_4)\n    True\n\n``acompose`` and ``sacompose`` instances flatten when nested:\n\n.. code:: python\n\n    \u003e\u003e\u003e acompose(f, acompose(f, f)).functions == (f, f, f)\n    True\n    \u003e\u003e\u003e acompose(sacompose(f, f), f).functions == (f, f, f)\n    True\n    \u003e\u003e\u003e sacompose(acompose(f, f), f).functions == (f, f, f)\n    True\n    \u003e\u003e\u003e sacompose(f, sacompose(f, f)).functions == (f, f, f)\n    True\n\nBut ``compose`` instances *don't* flatten when nested \ninto ``acompose`` and ``sacompose``, and vice versa:\n\n.. code:: python\n\n    \u003e\u003e\u003e acompose(g_of_f).functions\n    (compose(\u003cfunction g at 0x...\u003e, \u003cfunction f at 0x...\u003e),)\n    \u003e\u003e\u003e sacompose(g_of_f).functions\n    (compose(\u003cfunction g at 0x...\u003e, \u003cfunction f at 0x...\u003e),)\n    \u003e\u003e\u003e compose(acompose(g, f)).functions\n    (acompose(\u003cfunction g at 0x...\u003e, \u003cfunction f at 0x...\u003e),)\n    \u003e\u003e\u003e compose(sacompose(g, f)).functions\n    (sacompose(\u003cfunction g at 0x...\u003e, \u003cfunction f at 0x...\u003e),)\n\n``compose``, ``acompose``, and ``sacompose``\ninstances are all distinct types:\n\n.. code:: python\n\n    \u003e\u003e\u003e isinstance(g_of_f, compose)\n    True\n    \u003e\u003e\u003e isinstance(g_of_f, (acompose, sacompose))\n    False\n    \u003e\u003e\u003e isinstance(async_times_16, acompose)\n    True\n    \u003e\u003e\u003e isinstance(async_times_16, (compose, sacompose))\n    False\n    \u003e\u003e\u003e isinstance(async_times_4, sacompose)\n    True\n    \u003e\u003e\u003e isinstance(async_times_4, (compose, acompose))\n    False\n","funding_links":[],"categories":["Awesome Functional Python"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmentalisttraceur%2Fpython-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmentalisttraceur%2Fpython-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmentalisttraceur%2Fpython-compose/lists"}