Skip to main content

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

Project description

pypi version travis build documentation status coverage hypothesis tested

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

Getting Started:

Install the latest stable version with pip:

$ pip install collectionish

A quick note about python version support:

collectionish works with python 3 and has been fully tested with python 3.7 and 3.8. There is no plan to support backwards compatability for python 2 or 3.5.

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 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 library wherever possible. We do doctests to keep documentation correct.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collectionish-0.3.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

collectionish-0.3.0-py2.py3-none-any.whl (9.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file collectionish-0.3.0.tar.gz.

File metadata

  • Download URL: collectionish-0.3.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for collectionish-0.3.0.tar.gz
Algorithm Hash digest
SHA256 59715d5b3d9f9e180d6bec619476221985a30d9545dffd9a03cfe81b85472166
MD5 04f41e5831112b63269b829997a0f95f
BLAKE2b-256 3504d29bac33854a1dbdb2d33a6b91b9bfa8839abccd940bfd40bf7326ef558b

See more details on using hashes here.

File details

Details for the file collectionish-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: collectionish-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for collectionish-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 471a0e09294a532794d1f0510128b27f6fc4f3b598ddcfc6bfbd014c5eee4768
MD5 891bcc850df7b6359195a16de6d5d210
BLAKE2b-256 06a0752e828b1763ae31072a37e4d8896f0f2460e6837057de7c278b001bb1ab

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page