Skip to main content

Immutable constant namespaces with dataclass-like ergonomics

Reason this release was yanked:

metaclass error messed up other packages

Project description

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.

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

classicle-0.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

classicle-0.2.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file classicle-0.2.0.tar.gz.

File metadata

  • Download URL: classicle-0.2.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for classicle-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b8ff6dbc00bc547a2591d8958151004b74b19ab9816e56bf35bd2bb981d58aae
MD5 e6a06356307eeb9eaf2d238d8c1a2ae3
BLAKE2b-256 fcadd3d1670cb9995f219fbfc413ab417a99d4f7c895a16249a68eaf44bbeaa2

See more details on using hashes here.

File details

Details for the file classicle-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: classicle-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for classicle-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f2a6adcc194365379e5b8a09ec853e0e92c51677dc75eddcee78404cd69dee9
MD5 4dfa0ffd7c44a40c96e2f82e655430b1
BLAKE2b-256 86608abd55778c5254a5e5768bb9c66c6e5c0047691c9e48723b45b5e921aa06

See more details on using hashes here.

Supported by

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