Skip to main content

classicle

Provides immutable constant namespaces with dataclass-like ergonomics. See the Python discussion thread for context, motivation, and alternative approaches.

Example:

from classicle import FrozenSpace

class Config(FrozenSpace):
    HOST = "localhost"
    PORT: int = 8080  # add type hints only when you want them
    DEBUG = True


print(Config.HOST)  # "localhost"; Type checker knows this is a str
print(Config.PORT)  # 8080
config_dict = dict(Config)
# {'HOST': 'localhost', 'PORT': 8080, 'DEBUG': True}

# Iterate over attributes
for name, value in Config.items():
    print(f"{name} = {value}")

Features

  • Type checker friendly
  • No instantiation needed: The class itself is the namespace (cannot be instantiated)
  • Immutable: Attributes cannot be modified (at the top level) or deleted after creation
  • Mapping protocol: Supports dict(), len(), in, iteration, .items(), .keys(), .values()

Immutability

class Constants(FrozenSpace):
    PI = 3.14159
    E = 2.71828

# This will raise an AttributeError
try:
    Constants.PI = 3.14
except AttributeError as e:
    print(e)  # "Cannot modify attribute 'PI' on frozen namespace"

# This will also raise an AttributeError
try:
    del Constants.E
except AttributeError as e:
    print(e)  # "Cannot delete attribute 'E' on frozen namespace"

# Cannot instantiate FrozenSpace classes
try:
    instance = Constants()
except TypeError as e:
    print(e)  # "Cannot instantiate Constants..."

Installation

Install classicle: We're on pypi, so uv add classicle. If working directly on this repo, consider using the simplest-possible virtual environment.

Metadata

Release files for classicle 0.2.2

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

Source distribution (sdist)

Source distribution for classicle 0.2.2
File Size Uploaded
classicle-0.2.2.tar.gz 21.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for classicle 0.2.2
File Interpreter ABI Platform
classicle-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / classicle-0.2.2.tar.gz

Download URL classicle-0.2.2.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7e439164c8a644871c129cac5d2eaaddc4690fcf76a0ec54b48361dfee87db77
BLAKE2b-256 checksum
How to use checksums
98017d22a824036fa26f740a63c5b2af2337d9985de8e7fd6a30343c855acecd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Release files / classicle-0.2.2-py3-none-any.whl

Download URL classicle-0.2.2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8685bf857d03a455df72f8ddbc482c5ee2dcf2b2e0b1eaeb89336a862f8fabad
BLAKE2b-256 checksum
How to use checksums
77994885bf560088cf36493ce8676bf71146e179d92f41ecbf48dc76f50a430b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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