Skip to main content

collectionish

Collectionish is a pure python library extending the basic collection data types and operations for working with them.


pypi version build documentation status coverage

  • Free software: MIT license
  • Documentation: docs
  • Supported Python Versions: >=3.7

Getting Started:

Install the latest stable version with pip:

$ pip install collectionish

Checkout the docs:

It's best to checkout the docs. There you'll find detailed documentation of collectionish's features and lots of examples of how to use them.

--

What's is it?

Python is a wonderful language when it comes to extending inbuilt types and making things that quack. collectionish subscribes to the ideology that the behaviour of data structures belongs in data structures and that it's better and more graceful to bake the behavior into a type than to complicate surrounding business logic creating many more wtf moments and room for bugs to sneak in.

Python's own [collections][https://docs.python.org/library/collections.html] module is a great example. take defaultdict, how many times have you seen something like this?

pets = [('cat', 'tabby'),
        ('cat', 'ginger'),
        ('dog', 'beagle'),
        ('dog', 'poodle'),
        ('lizard', 'gecko')
       ]

pet_dict = {}
for typ, subtyp in pets:
    try:
        pet_dict[typ].append(subtyp)
    except KeyError:
        # now we'll need to make an comment to explain...
        # if the key doesn't exist pet_dict we make a new
        # list containing the pet's subtype
        pet_dict[typ] = [subtyp]

vs:

from collections import defaultdict

pet_dict = defaultdict(list)
for typ, subtyp in pets:
    pet_dict[typ].append(subtyp)

collectionish adds some extra collections such like AttyDict (a straightforward recursive dot access dict ) and UniqueTuple ( a tuple of unique items that remembers insertion order). New collections will be added fairly regularly on the basis that they are generic enough and useful enough that i find myself repeating them in other projects.

In addition to data structures collectionish also provides some operations for working with data structures (from both standard python and collections) like the recursive getters and setters collectionish.ops.


Principles:

useful enough:
Inspirations for data structures should come from stuff we've written or needed before at some point.

generic enough:
To be extended within reason.

specific enough:
To be clear about what things do. We don't aim to make the data structure or stand in for a pandas dataframe that does everything.

intuitive enough:
type hinting should generally work the same as it does with parent types, signatures should not be wildly different, obvious magic methods or such as __iter__ should not generally be missing from data types.

documented enough:
All public structures and ops should be documented and have doctest examples so we know its correct and It should be fairly obvious from somethings name what it is.

tested more than enough:
we test with the excellent [hypothesis][https://github.com/HypothesisWorks/hypothesis] library wherever possible. We do doctests to keep documentation correct.

Metadata

Release files for collectionish 0.5.0

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

Source distribution (sdist)

Source distribution for collectionish 0.5.0
File Size Uploaded
collectionish-0.5.0.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for collectionish 0.5.0
File Interpreter ABI Platform
collectionish-0.5.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 27.2 kB

Release files / collectionish-0.5.0.tar.gz

Download URL collectionish-0.5.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a710f79a0b5fb1e9b30f69afb63629b1d14bc9b2b540c2b76c3ef6e1b1349623
BLAKE2b-256 checksum
How to use checksums
b3d701a60d4ce7059f7c63fa5e14c887a1bd3b95cbc8b131dd549c3cf4b5e6f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

Release files / collectionish-0.5.0-py2.py3-none-any.whl

Download URL collectionish-0.5.0-py2.py3-none-any.whl
Size 12.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
67838d3dc07128731a1f9360253e3a4ef2eca8afc39c5128210f25758ed10dee
BLAKE2b-256 checksum
How to use checksums
6ba14f9b0f389272955040d8e52f7b8abda1c6fc4c4b4d2f726a8c91a76e772d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

1 release file

0.2.0

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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