Skip to main content

creek

A simple facade for streams: wrap an iterable, layer transformations on it, and read unbounded streams as if they were lists.

To install: pip install creek

The smallest complete example: a Creek subclass that parses each line of a file-like stream.

>>> from io import StringIO
>>> from creek import Creek
>>> class CsvCreek(Creek):
...     def data_to_obj(self, line):
...         return [x.strip() for x in line.strip().split(',')]
>>> stream = CsvCreek(StringIO('a, b, c\n1,2, 3\n'))
>>> list(stream)
[['a', 'b', 'c'], ['1', '2', '3']]

For AI agents

creek ships tooling for coding agents. If you are one, start here.

The documentation, machine-readable: llms.txt indexes every page; creek.md is the whole documentation in one file; every page has a .md twin; objects.inv maps symbols to URLs.

If you are a control freak, the rest of this README is written for you, starting at The Creek layers.

The Creek layers

The Creek base class offers a layer-able wrap of the stream interface. There are three layering methods, pre_iter, data_to_obj and post_iter, each the identity by default. Iterating over a creek is exactly:

yield from self.post_iter(map(self.data_to_obj, self.pre_iter(self.stream)))
  • pre_iter(stream): prepare and/or filter the raw stream (skip a header, enumerate lines, ...)
  • data_to_obj(item): transform each item the stream yields
  • post_iter(objs): further process or filter the transformed objects

Everything else (seek, close, the context manager protocol, ...) is delegated to the wrapped stream:

>>> src = StringIO(
... '''a, b, c
... 1,2, 3
... 4, 5,6
... '''
... )
>>> class MyCreek(Creek):
...     def data_to_obj(self, line):
...         return [x.strip() for x in line.strip().split(',')]
...
>>> stream = MyCreek(src)
>>> list(stream)
[['a', 'b', 'c'], ['1', '2', '3'], ['4', '5', '6']]
>>> stream.seek(0)  # oh!... but we consumed the stream already, so let's go back to the beginning
0
>>> list(stream)
[['a', 'b', 'c'], ['1', '2', '3'], ['4', '5', '6']]
>>> stream.seek(0)  # rewind again
0
>>> next(stream)
['a', 'b', 'c']
>>> next(stream)
['1', '2', '3']

Let's add a filter! There are two kinds you can use: one applied to the line before the data is transformed by data_to_obj (in pre_iter), and one applied after, to the objects (in post_iter).

>>> src = StringIO(
...     '''a, b, c
... 1,2, 3
... 4, 5,6
... ''')
>>> class MyFilteredCreek(MyCreek):
...     def post_iter(self, objs):
...         yield from filter(lambda obj: str.isnumeric(obj[0]), objs)
>>>
>>> s = MyFilteredCreek(src)
>>> list(s)
[['1', '2', '3'], ['4', '5', '6']]
>>> s.seek(0)
0
>>> list(s)
[['1', '2', '3'], ['4', '5', '6']]
>>> s.seek(0)
0
>>> next(s)
['1', '2', '3']

Recipes:

  • pre_iter: itertools.islice to skip header lines
  • pre_iter: enumerate to get line indices in the stream iterator
  • pre_iter = functools.partial(map, line_pre_proc_func) to preprocess all lines with line_pre_proc_func
  • pre_iter: functools.partial(filter, condition) to filter before data_to_obj
  • post_iter: itertools.chain.from_iterable to flatten a chunked/segmented stream
  • post_iter: functools.partial(filter, condition) to filter the yielded objects

Beyond Creek

  • InfiniteSeq and IndexedBuffer (creek.infinite_sequence): list-like s[i:j] access to an unbounded stream, through a bounded buffer.
  • BufferStats and Segmenter (creek.tools): rolling-window statistics and segmentation of a stream.
  • dynamically_index and filter_and_index_stream (creek.tools): enumerate with a custom index rule, and filtered indexing.

Documentation

Metadata

Release files for creek 0.1.37

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

Source distribution (sdist)

Source distribution for creek 0.1.37
File Size Uploaded Provenance Actions
creek-0.1.37.tar.gz 46.2 kB Without provenance Details for creek-0.1.37.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for creek 0.1.37
File Interpreter ABI Platform Actions
creek-0.1.37-py3-none-any.whl Python 3 none any Details for creek-0.1.37-py3-none-any.whl

Total release size: 95.8 kB

Release files / creek-0.1.37.tar.gz

Download URL creek-0.1.37.tar.gz
Size 46.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dfdea3a96f61384108f3123f5cce17f61e1c82d0df6aee08bdecb877179c7ab8
BLAKE2b-256 checksum
How to use checksums
fa362d7e8cbc2e7ff04f5b48113d6627aea5799e286ab18d8f2bfdf85389a813
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / creek-0.1.37-py3-none-any.whl

Download URL creek-0.1.37-py3-none-any.whl
Size 49.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a153ef39766d4bb8e52b538efd513e3ef76ae8e122e6ee987c47e1d593dad07b
BLAKE2b-256 checksum
How to use checksums
d6dba9e4c5d2d1496abeddb5e8edadf996239ecef8337f17080838cfc64b959f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for creek 0.1.37

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.37 This release

2 release files No provenance

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