Skip to main content

funcy-chain

Simple Python data processing using method-chaining style and the funcy library.

>>> users = [
...   { 'first_name': 'barney',  'age': 36 },
...   { 'first_name': 'fred',    'age': 40 },
...   { 'first_name': 'pebbles', 'age': 1 }
... ]
>>> (Chain(users)
...     .sort(key=itemgetter("age"))
...     .map(itemgetter("first_name"))
...     .thru(lambda names: names + ["wilma"])
...     .map(str.capitalize)
... ).value
['Pebbles', 'Barney', 'Fred', 'Wilma']

Why?

  • Method chaining can make some multi-stage data processing easier to read and write.
  • Funcy is great, but doesn't support method chaining.
  • Other method-chaining implementations have too much "magic", are overly complex, and support too many ways of doing one thing. (see: pydash, fluentpy)
  • Being simple and straightforward is a great boon, making it easier to reason about code, debug, etc.

Key Features

  • Useful out of the box, supporting built-in, stdlib and funcy functions (see below).
  • Easy to compose with additional utilities (see Chain.thru()).
  • Both "immediate" (list-based) and "lazy" (iterator-based) computations supported, via parallel Chain and IterChain classes.
>>> from funcy_chain import Chain
>>> (Chain([1, 2, 3, 7, 6, 5, 4])
...     .without(3)
...     .filter(lambda x: x > 2)
...     .remove(lambda x: x > 6)
...     .sort(reverse=True)
... ).value
[6, 5, 4]

Supported Methods

built-in

Note: funcy's map and filter are used rather than the built-ins.

stdlib

funcy

The following is a sub-set of the funcy cheat sheet including only functions supported as methods on Chain and IterChain objects.

Sequences

Slicedrop take rest butlast takewhile dropwhile split_at split_by
Transformmap mapcat keep pluck pluck_attr invoke
Filterfilter remove keep distinct where without
Joinconcat flatten mapcat interleave interpose
Partitionchunks partition partition_by split_at split_by
Groupsplit count_by count_reps group_by group_by_keys group_values
Aggregatewith_prev with_next accumulate reductions sums
Iteratepairwise with_prev with_next zip_values zip_dicts

Collections

Joinjoin join_with
Transformwalk walk_keys walk_values
Filterselect select_keys select_values compact
Dictsflip pluck where project zip_values zip_dicts

Metadata

Release files for funcy-chain 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for funcy-chain 0.3.1
File Size Uploaded
funcy_chain-0.3.1.tar.gz 15.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for funcy-chain 0.3.1
File Interpreter ABI Platform
funcy_chain-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / funcy_chain-0.3.1.tar.gz

Download URL funcy_chain-0.3.1.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b263356feb25206c21589741347b20304c54cd4eaaddfda21624f1fd996540e6
BLAKE2b-256 checksum
How to use checksums
ecf456d3ae9f174940a3d33f5761740b4613135134922f11b4555f1c3b7d9503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / funcy_chain-0.3.1-py3-none-any.whl

Download URL funcy_chain-0.3.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b016104e2faa81deacab4e3924d960a068b980e008fe6d8ba2969f56060e9651
BLAKE2b-256 checksum
How to use checksums
448b74fe7596e8b8f69a8c791f33237563e0115b32aa787e0672f15482222cbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page