Skip to main content

Implementation of some concepts from category theory

Project description

master pipeline master coverage

Pycategories is a Python 3 library that implements ideas from category theory, such as monoids, functors, and monads. It provides a Haskell-influenced interface for defining instances of those typeclasses and defines several right out of the box, for example the Maybe monad:

>>> from categories import apply
>>> from categories.maybe import Just, Nothing
>>> f = Just(lambda x: x ** 2)
>>> x = Just(17)
>>> apply(f, x)
>>> apply(f, Nothing())

Or to define your own instance of a typeclass:

>>> from categories import mappend, mempty, monoid
>>> monoid.instance(dict, lambda: {}, lambda a, b: dict(**a, **b))
>>> mappend({'foo': 'bar'}, {'rhu': 'barb'})
{'foo': 'bar', 'rhu': 'barb'}


pip install pycategories

To clone the repo and install dependencies for development:

git clone
cd pycategories
pip install -e .[dev]

Support and Contributing


Pycategories is licensed under the MIT License


Documentation is available at

Project details

Download files

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

Files for pycategories, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pycategories-1.2.0-py3-none-any.whl (13.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pycategories-1.2.0.tar.gz (16.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page