Skip to main content

Scala-like CaseClasses for Python

Project description

Build Status

Zero-dependency scala-like case classes for Python 2 + 3.


  • Simple usage: Just inherit from case_class.CaseClass

  • Simple Installation: Zero dependencies

  • plays well with inheritance
    • CaseClass and AbstractCaseClass` usable as a Mix-In

    • Case-to-case inheritance forbidden by default
      • use AbstractCaseClass to allow only subclasses to be instantiated

      • use InheritableCaseClass to override allow both super and subclasses to be instantiated.`

    • also plays well with Multiple Inheritance * super() calls still work as expected

  • equality based on arguments
    • calls constructor only once per combination of arguments

    • works with == operator and is (referential equality) operator.

  • automatic repr() function

  • works in both Python 2 and Python 3!


This package is published on the Python Package Index Installation can be done simply via pip:

pip install case_class

Alternatively, clone this repository and run

git clone
python install


# Import the CaseClass module
from case_class import CaseClass

# Create a symbol case class
class Symbol(CaseClass):
    def __init__(self, name): = name

# Create an instance
x = Symbol("x")
print(x)  # Symbol('x')

# And create another one
also_x = Symbol('x')
print(x == also_x)  # equality via operator
print(x is also_x)  # referential equality

Another example can be found in

License + Acknowledgements

This module and associated documentation is Copyright (c) Tom Wiesing 2016 and licensed under the MIT license, see license for details. Small parts of the code are adapted from the six module, which is Copyright (c) 2010-2015 Benjamin Peterson.

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

case_class-0.0.8.tar.gz (12.2 kB view hashes)

Uploaded source

Built Distributions

case_class-0.0.8-py3-none-any.whl (15.0 kB view hashes)

Uploaded 3 5

case_class-0.0.8-py2-none-any.whl (15.0 kB view hashes)

Uploaded 2 7

Supported by

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