funcy

A fancy and practical functional tools

https://github.com/suor/funcy

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.9%) to scientific vocabulary

Keywords

functional-programming python utilities

Keywords from Contributors

openbsd memory freebsd disk asyncio distributed apps templates views closember
Last synced: 6 months ago · JSON representation

Repository

A fancy and practical functional tools

Basic Info
  • Host: GitHub
  • Owner: Suor
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 1.04 MB
Statistics
  • Stars: 3,427
  • Watchers: 70
  • Forks: 147
  • Open Issues: 16
  • Releases: 0
Topics
functional-programming python utilities
Created over 13 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.rst

Funcy |Build Status|
=====

A collection of fancy functional tools focused on practicality.

Inspired by clojure, underscore and my own abstractions. Keep reading to get an overview
or `read the docs `_.
Or jump directly to `cheatsheet `_.

Works with Python 3.4+ and pypy3.


Installation
-------------

::

    pip install funcy


Overview
--------------

Import stuff from funcy to make things happen:

.. code:: python

    from funcy import whatever, you, need


Merge collections of same type
(works for dicts, sets, lists, tuples, iterators and even strings):

.. code:: python

    merge(coll1, coll2, coll3, ...)
    join(colls)
    merge_with(sum, dict1, dict2, ...)


Walk through collection, creating its transform (like map but preserves type):

.. code:: python

    walk(str.upper, {'a', 'b'})            # {'A', 'B'}
    walk(reversed, {'a': 1, 'b': 2})       # {1: 'a', 2: 'b'}
    walk_keys(double, {'a': 1, 'b': 2})    # {'aa': 1, 'bb': 2}
    walk_values(inc, {'a': 1, 'b': 2})     # {'a': 2, 'b': 3}


Select a part of collection:

.. code:: python

    select(even, {1,2,3,10,20})                  # {2,10,20}
    select(r'^a', ('a','b','ab','ba'))           # ('a','ab')
    select_keys(callable, {str: '', None: None}) # {str: ''}
    compact({2, None, 1, 0})                     # {1,2}


Manipulate sequences:

.. code:: python

    take(4, iterate(double, 1)) # [1, 2, 4, 8]
    first(drop(3, count(10)))   # 13

    lremove(even, [1, 2, 3])    # [1, 3]
    lconcat([1, 2], [5, 6])     # [1, 2, 5, 6]
    lcat(map(range, range(4)))  # [0, 0, 1, 0, 1, 2]
    lmapcat(range, range(4))    # same
    flatten(nested_structure)   # flat iter
    distinct('abacbdd')         # iter('abcd')

    lsplit(odd, range(5))       # ([1, 3], [0, 2, 4])
    lsplit_at(2, range(5))      # ([0, 1], [2, 3, 4])
    group_by(mod3, range(5))    # {0: [0, 3], 1: [1, 4], 2: [2]}

    lpartition(2, range(5))     # [[0, 1], [2, 3]]
    chunks(2, range(5))         # iter: [0, 1], [2, 3], [4]
    pairwise(range(5))          # iter: [0, 1], [1, 2], ...


And functions:

.. code:: python

    partial(add, 1)             # inc
    curry(add)(1)(2)            # 3
    compose(inc, double)(10)    # 21
    complement(even)            # odd
    all_fn(isa(int), even)      # is_even_int

    one_third = rpartial(operator.div, 3.0)
    has_suffix = rcurry(str.endswith, 2)


Create decorators easily:

.. code:: python

    @decorator
    def log(call):
        print(call._func.__name__, call._args)
        return call()


Abstract control flow:

.. code:: python

    walk_values(silent(int), {'a': '1', 'b': 'no'})
    # => {'a': 1, 'b': None}

    @once
    def initialize():
        "..."

    with suppress(OSError):
        os.remove('some.file')

    @ignore(ErrorRateExceeded)
    @limit_error_rate(fails=5, timeout=60)
    @retry(tries=2, errors=(HttpError, ServiceDown))
    def some_unreliable_action(...):
        "..."

    class MyUser(AbstractBaseUser):
        @cached_property
        def public_phones(self):
            return self.phones.filter(public=True)


Ease debugging:

.. code:: python

    squares = {tap(x, 'x'): tap(x * x, 'x^2') for x in [3, 4]}
    # x: 3
    # x^2: 9
    # ...

    @print_exits
    def some_func(...):
        "..."

    @log_calls(log.info, errors=False)
    @log_errors(log.exception)
    def some_suspicious_function(...):
        "..."

    with print_durations('Creating models'):
        Model.objects.create(...)
        # ...
    # 10.2 ms in Creating models


And `much more `_.


Dive in
-------

Funcy is an embodiment of ideas I explain in several essays:

- `Why Every Language Needs Its Underscore `_
- `Functional Python Made Easy `_
- `Abstracting Control Flow `_
- `Painless Decorators `_

Related Projects
----------------

- https://pypi.org/project/funcy-chain/
- https://pypi.org/project/funcy-pipe/

Running tests
--------------

To run the tests using your default python:

::

    pip install -r test_requirements.txt
    py.test

To fully run ``tox`` you need all the supported pythons to be installed. These are
3.4+ and PyPy3. You can run it for particular environment even in absense
of all of the above::

    tox -e py310
    tox -e pypy3
    tox -e lint


.. |Build Status| image:: https://github.com/Suor/funcy/actions/workflows/test.yml/badge.svg
   :target: https://github.com/Suor/funcy/actions/workflows/test.yml?query=branch%3Amaster

Owner

  • Name: Alexander Schepanovski
  • Login: Suor
  • Kind: user

GitHub Events

Total
  • Issues event: 6
  • Watch event: 91
  • Issue comment event: 2
  • Pull request event: 2
  • Fork event: 6
Last Year
  • Issues event: 6
  • Watch event: 91
  • Issue comment event: 2
  • Pull request event: 2
  • Fork event: 6

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 965
  • Total Committers: 33
  • Avg Commits per committer: 29.242
  • Development Distribution Score (DDS): 0.055
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Alexander Schepanovski s****b@g****m 912
Michael Bianco i****y@g****m 6
Bruno Alla a****o@g****m 4
Eric Prykhodko e****o@g****m 4
suor s****r@s****) 4
Marcus McCurdy m****y@g****m 3
Tim Gates t****s@i****m 3
Lukasz Dobrzanski l****i@g****m 2
Tal Einat 5****t 2
rocco66 r****x@g****m 2
Petr Melnikov p****v@z****a 1
Paul Melnikow p****w@b****m 1
Jim Xue d****r@g****m 1
Denys Zorinets d****s@b****m 1
Aleksei Voronov d****n@g****m 1
Andrew Walker w****b@g****m 1
Gábor Lipták g****k@g****m 1
Kale Kundert k****e@t****t 1
Laurens Duijvesteijn g****t@d****o 1
Nathan Leiby n****y@g****m 1
Niels Lemmens d****n@g****m 1
Ruan Comelli r****i@g****m 1
Sahand Saba s****s@g****m 1
Saugat Pachhai s****i@o****m 1
Swaroop s****p@s****m 1
The Gitter Badger b****r@g****m 1
Tomáš Chvátal t****l@g****m 1
Zakhar Zibarov z****r@y****u 1
bersbersbers 1****s 1
tsouvarev t****v@m****u 1
and 3 more...

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 63
  • Total pull requests: 69
  • Average time to close issues: 3 months
  • Average time to close pull requests: 24 days
  • Total issue authors: 47
  • Total pull request authors: 41
  • Average comments per issue: 3.89
  • Average comments per pull request: 2.09
  • Merged pull requests: 35
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • bersbersbers (4)
  • ADR-007 (4)
  • taleinat (4)
  • ruancomelli (3)
  • adrian-dankiv (2)
  • vspinu (2)
  • antoine-gallix (2)
  • timgates42 (2)
  • ghost (2)
  • eykd (2)
  • richard-engineering (2)
  • meh-wzdech (1)
  • javadba (1)
  • luismsmendonca (1)
  • despawnerer (1)
Pull Request Authors
  • iloveitaly (24)
  • Suor (5)
  • RP-pl (4)
  • antoine-gallix (3)
  • taleinat (3)
  • timgates42 (3)
  • maiyajj (2)
  • paulmelnikow (2)
  • python-mutation-testing (2)
  • browniebroke (2)
  • swaroopch (2)
  • duijf (1)
  • radeklat (1)
  • deniszorinets (1)
  • despawnerer (1)
Top Labels
Issue Labels
looking for more interest (7) design decision needed (1)
Pull Request Labels
looking for more interest (2) design decision needed (1)

Packages

  • Total packages: 20
  • Total downloads:
    • pypi 3,030,351 last-month
  • Total docker downloads: 83,670,525
  • Total dependent packages: 136
    (may contain duplicates)
  • Total dependent repositories: 1,896
    (may contain duplicates)
  • Total versions: 91
  • Total maintainers: 2
pypi.org: funcy

A fancy and practical functional tools

  • Versions: 51
  • Dependent Packages: 122
  • Dependent Repositories: 1,890
  • Downloads: 3,030,351 Last month
  • Docker Downloads: 83,670,525
Rankings
Dependent packages count: 0.2%
Downloads: 0.3%
Dependent repos count: 0.3%
Docker downloads count: 0.4%
Average: 1.1%
Stargazers count: 1.3%
Forks count: 4.1%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.18: py3-funcy-pyc

Precompiled Python bytecode for py3-funcy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 3.4%
Stargazers count: 4.3%
Forks count: 9.3%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.18: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 3.4%
Stargazers count: 4.3%
Forks count: 9.3%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.13: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 2.8%
Forks count: 6.6%
Average: 7.2%
Dependent packages count: 19.5%
Maintainers (1)
Last synced: 7 months ago
alpine-edge: py3-funcy

A fancy and practical functional tools

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 4.3%
Average: 7.3%
Forks count: 10.4%
Dependent packages count: 14.6%
Maintainers (1)
Last synced: 7 months ago
alpine-edge: py3-funcy-pyc

Precompiled Python bytecode for py3-funcy

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 4.5%
Average: 7.3%
Forks count: 10.6%
Dependent packages count: 14.3%
Maintainers (1)
Last synced: 7 months ago
alpine-v3.12: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 2.5%
Forks count: 5.6%
Average: 7.4%
Dependent packages count: 21.5%
Maintainers (1)
Last synced: 7 months ago
alpine-v3.14: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 2.9%
Forks count: 6.6%
Average: 7.8%
Dependent packages count: 21.7%
Maintainers (1)
Last synced: 7 months ago
alpine-v3.15: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 3.1%
Forks count: 6.9%
Average: 8.9%
Dependent packages count: 25.6%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.16: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 3.3%
Forks count: 7.2%
Average: 9.5%
Dependent packages count: 27.3%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.17: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 4.0%
Forks count: 8.9%
Average: 10.0%
Dependent packages count: 27.3%
Maintainers (1)
Last synced: 7 months ago
conda-forge.org: funcy
  • Versions: 16
  • Dependent Packages: 14
  • Dependent Repositories: 6
Rankings
Dependent packages count: 4.5%
Stargazers count: 7.3%
Average: 10.3%
Dependent repos count: 13.8%
Forks count: 15.6%
Last synced: 7 months ago
alpine-v3.19: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.19: py3-funcy-pyc

Precompiled Python bytecode for py3-funcy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.20: py3-funcy-pyc

Precompiled Python bytecode for py3-funcy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.20: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago
alpine-v3.22: py3-funcy-pyc

Precompiled Python bytecode for py3-funcy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 7 months ago
alpine-v3.22: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 7 months ago
alpine-v3.21: py3-funcy

A fancy and practical functional tools

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 7 months ago
alpine-v3.21: py3-funcy-pyc

Precompiled Python bytecode for py3-funcy

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/test.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
docs/requirements.txt pypi
  • Sphinx ==4.3.0
  • sphinx-rtd-theme ==0.5.1
test_requirements.txt pypi
  • more-itertools ==4.0.0 test
  • pytest ==3.9.3 test
  • pytest ==6.2.5 test
  • typing * test
  • whatever ==0.6 test