Skip to content

Compclasses

Licence Ruff

Like dataclasses, but for composition.

Favor object composition over class inheritance

As the Gang of Four (probably) said.

However when we use composition in Python, we cannot access methods directly from the composed class, and we either re-define these methods from scratch, or access them using chaining.

Compclasses enables composition and delegation of methods, making it easier to work with complex object structures.


Documentation | Source Code


Alpha Notice

This codebase is experimental and is working for my use cases. It is very probable that there are cases not covered and for which everything breaks. If you find them, please feel free to open an issue in the issue page of the repo.

Installation

The library is dependency-free, it only uses built-in modules from the Python Standard Library.

compclasses is published as a Python package on pypi, and it can be installed with pip, ideally by using a virtual environment (suggested option), or directly from source using git, or with a local clone:

python -m pip install compclasses
python -m pip install git+https://github.com/FBruzzesi/compclasses.git
git clone https://github.com/FBruzzesi/compclasses.git
cd compclasses
python -m pip install .

License

The project has a MIT Licence