{"id":17959271,"url":"https://github.com/suor/funcy","last_synced_at":"2025-05-13T00:32:06.696Z","repository":{"id":5038650,"uuid":"6198326","full_name":"Suor/funcy","owner":"Suor","description":"A fancy and practical functional tools","archived":false,"fork":false,"pushed_at":"2024-08-20T20:06:24.000Z","size":1094,"stargazers_count":3409,"open_issues_count":16,"forks_count":146,"subscribers_count":70,"default_branch":"master","last_synced_at":"2025-03-18T09:48:08.916Z","etag":null,"topics":["functional-programming","python","utilities"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"pilu/web-app-theme","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Suor.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG","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}},"created_at":"2012-10-13T00:44:57.000Z","updated_at":"2025-03-15T19:24:07.000Z","dependencies_parsed_at":"2023-02-18T14:15:47.708Z","dependency_job_id":"e8aa6aaf-2688-4411-be9f-033e14f75d6b","html_url":"https://github.com/Suor/funcy","commit_stats":{"total_commits":964,"total_committers":33,"mean_commits":29.21212121212121,"dds":0.05497925311203322,"last_synced_commit":"859056d039adea75c1c3550286437ce0b612fe92"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Suor%2Ffuncy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Suor%2Ffuncy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Suor%2Ffuncy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Suor%2Ffuncy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Suor","download_url":"https://codeload.github.com/Suor/funcy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250492395,"owners_count":21439521,"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":["functional-programming","python","utilities"],"created_at":"2024-10-29T11:02:03.653Z","updated_at":"2025-04-23T18:39:55.566Z","avatar_url":"https://github.com/Suor.png","language":"Python","readme":"Funcy |Build Status|\n=====\n\nA collection of fancy functional tools focused on practicality.\n\nInspired by clojure, underscore and my own abstractions. Keep reading to get an overview\nor `read the docs \u003chttp://funcy.readthedocs.org/\u003e`_.\nOr jump directly to `cheatsheet \u003chttp://funcy.readthedocs.io/en/stable/cheatsheet.html\u003e`_.\n\nWorks with Python 3.4+ and pypy3.\n\n\nInstallation\n-------------\n\n::\n\n    pip install funcy\n\n\nOverview\n--------------\n\nImport stuff from funcy to make things happen:\n\n.. code:: python\n\n    from funcy import whatever, you, need\n\n\nMerge collections of same type\n(works for dicts, sets, lists, tuples, iterators and even strings):\n\n.. code:: python\n\n    merge(coll1, coll2, coll3, ...)\n    join(colls)\n    merge_with(sum, dict1, dict2, ...)\n\n\nWalk through collection, creating its transform (like map but preserves type):\n\n.. code:: python\n\n    walk(str.upper, {'a', 'b'})            # {'A', 'B'}\n    walk(reversed, {'a': 1, 'b': 2})       # {1: 'a', 2: 'b'}\n    walk_keys(double, {'a': 1, 'b': 2})    # {'aa': 1, 'bb': 2}\n    walk_values(inc, {'a': 1, 'b': 2})     # {'a': 2, 'b': 3}\n\n\nSelect a part of collection:\n\n.. code:: python\n\n    select(even, {1,2,3,10,20})                  # {2,10,20}\n    select(r'^a', ('a','b','ab','ba'))           # ('a','ab')\n    select_keys(callable, {str: '', None: None}) # {str: ''}\n    compact({2, None, 1, 0})                     # {1,2}\n\n\nManipulate sequences:\n\n.. code:: python\n\n    take(4, iterate(double, 1)) # [1, 2, 4, 8]\n    first(drop(3, count(10)))   # 13\n\n    lremove(even, [1, 2, 3])    # [1, 3]\n    lconcat([1, 2], [5, 6])     # [1, 2, 5, 6]\n    lcat(map(range, range(4)))  # [0, 0, 1, 0, 1, 2]\n    lmapcat(range, range(4))    # same\n    flatten(nested_structure)   # flat iter\n    distinct('abacbdd')         # iter('abcd')\n\n    lsplit(odd, range(5))       # ([1, 3], [0, 2, 4])\n    lsplit_at(2, range(5))      # ([0, 1], [2, 3, 4])\n    group_by(mod3, range(5))    # {0: [0, 3], 1: [1, 4], 2: [2]}\n\n    lpartition(2, range(5))     # [[0, 1], [2, 3]]\n    chunks(2, range(5))         # iter: [0, 1], [2, 3], [4]\n    pairwise(range(5))          # iter: [0, 1], [1, 2], ...\n\n\nAnd functions:\n\n.. code:: python\n\n    partial(add, 1)             # inc\n    curry(add)(1)(2)            # 3\n    compose(inc, double)(10)    # 21\n    complement(even)            # odd\n    all_fn(isa(int), even)      # is_even_int\n\n    one_third = rpartial(operator.div, 3.0)\n    has_suffix = rcurry(str.endswith, 2)\n\n\nCreate decorators easily:\n\n.. code:: python\n\n    @decorator\n    def log(call):\n        print(call._func.__name__, call._args)\n        return call()\n\n\nAbstract control flow:\n\n.. code:: python\n\n    walk_values(silent(int), {'a': '1', 'b': 'no'})\n    # =\u003e {'a': 1, 'b': None}\n\n    @once\n    def initialize():\n        \"...\"\n\n    with suppress(OSError):\n        os.remove('some.file')\n\n    @ignore(ErrorRateExceeded)\n    @limit_error_rate(fails=5, timeout=60)\n    @retry(tries=2, errors=(HttpError, ServiceDown))\n    def some_unreliable_action(...):\n        \"...\"\n\n    class MyUser(AbstractBaseUser):\n        @cached_property\n        def public_phones(self):\n            return self.phones.filter(public=True)\n\n\nEase debugging:\n\n.. code:: python\n\n    squares = {tap(x, 'x'): tap(x * x, 'x^2') for x in [3, 4]}\n    # x: 3\n    # x^2: 9\n    # ...\n\n    @print_exits\n    def some_func(...):\n        \"...\"\n\n    @log_calls(log.info, errors=False)\n    @log_errors(log.exception)\n    def some_suspicious_function(...):\n        \"...\"\n\n    with print_durations('Creating models'):\n        Model.objects.create(...)\n        # ...\n    # 10.2 ms in Creating models\n\n\nAnd `much more \u003chttp://funcy.readthedocs.org/\u003e`_.\n\n\nDive in\n-------\n\nFuncy is an embodiment of ideas I explain in several essays:\n\n- `Why Every Language Needs Its Underscore \u003chttps://suor.github.io/blog/2014/06/22/why-every-language-needs-its-underscore/\u003e`_\n- `Functional Python Made Easy \u003chttps://suor.github.io/blog/2013/10/13/functional-python-made-easy/\u003e`_\n- `Abstracting Control Flow \u003chttps://suor.github.io/blog/2013/10/08/abstracting-control-flow/\u003e`_\n- `Painless Decorators \u003chttps://suor.github.io/blog/2013/11/03/painless-decorators/\u003e`_\n\nRelated Projects\n----------------\n\n- https://pypi.org/project/funcy-chain/\n- https://pypi.org/project/funcy-pipe/\n\nRunning tests\n--------------\n\nTo run the tests using your default python:\n\n::\n\n    pip install -r test_requirements.txt\n    py.test\n\nTo fully run ``tox`` you need all the supported pythons to be installed. These are\n3.4+ and PyPy3. You can run it for particular environment even in absense\nof all of the above::\n\n    tox -e py310\n    tox -e pypy3\n    tox -e lint\n\n\n.. |Build Status| image:: https://github.com/Suor/funcy/actions/workflows/test.yml/badge.svg\n   :target: https://github.com/Suor/funcy/actions/workflows/test.yml?query=branch%3Amaster\n","funding_links":[],"categories":["Awesome Functional Python"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuor%2Ffuncy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuor%2Ffuncy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuor%2Ffuncy/lists"}