ConstSpace 🚀
ConstSpace is an ultra-lightweight Python library for defining read-only, non-instantiable, and type-safe constant namespaces.
It is designed to eliminate the verbosity of Python's Enum (which requires .value access) and the lack of protection in plain classes.
🌟 Key Features
- Zero
.valueOverhead: Access constants directly. What you see is what you get, with perfect IDE autocompletion. - Class-Level Read-Only Protection: Uses metaclasses to block any attempt to modify or delete class attributes at runtime.
- Strict Non-instantiability: Ensures classes are used purely as namespaces. Attempting to instantiate will raise a
TypeError. - Unified Type Grouping: The decorator automatically injects a base class, allowing you to use
ConstSpaceTypefor clean type hinting and management. - Seamless Integration: Supports direct references between attributes during definition and works perfectly with static type checkers like MyPy.
📦 Installation
pip install constspace
🚀 Quick Start
1. Define Your Constant Space
from constspace import constspace
@constspace
class ServiceConfig:
API_KEY = "v1_sec_123"
TIMEOUT = 60
# Reference attributes directly without .value or self
SIGNATURE = f"prefix_{API_KEY}_suffix"
2. Security & Constraints
# ✅ Normal Access
print(ServiceConfig.SIGNATURE)
# ❌ Modify attribute -> Raises AttributeError
ServiceConfig.API_KEY = "new_key"
# ❌ Instantiate -> Raises TypeError
cfg = ServiceConfig()
3. Type Hinting & Management
from typing import List
from constspace import constspace, ConstSpaceType
@constspace
class MySQL:
PORT = 3306
@constspace
class Redis:
PORT = 6379
# Use ConstSpaceType (alias for Type[ConstSpace]) for constraints
def print_port(cfg: ConstSpaceType):
print(f"Port is: {cfg.PORT}")
configs: List[ConstSpaceType] = [MySQL, Redis]
for c in configs:
print_port(c)
🧐 Why ConstSpace?
| Feature | ConstSpace | Enum | Dataclass (frozen) |
|---|---|---|---|
| Easy Access | ✅ Direct Value | ❌ Requires .value |
✅ Direct Value |
| Block Instance | ✅ Strictly Enforced | ❌ Allowed by default | ❌ Allowed by default |
| Class Attribute Protection | ✅ Strictly Read-only | ❌ Allowed to modify | ❌ Only protects instances |
| Type Integrity | ✅ Original Types | ❌ Enum Member Type | ✅ Original Types |
📜 License
MIT License.
Metadata
Release files for constspace 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| constspace-0.1.5.tar.gz | 7.7 kB | Without provenance | Details for constspace-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| constspace-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for constspace-0.1.5-py3-none-any.whl |
Total release size: 13.0 kB
Release files / constspace-0.1.5.tar.gz
| Download URL | constspace-0.1.5.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e11caeb056ace8b01ae3926d4ee3b61184151c3c90dd747e963b9b62ba8c8961
|
|
BLAKE2b-256 checksum How to use checksums |
ae06927c24d61320d04f3c084ba74bfa21074c36d220070fbd2ca4c60dd3de47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / constspace-0.1.5-py3-none-any.whl
| Download URL | constspace-0.1.5-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c821e0b4f3e634a5a761be6b200291c0a2b5bdbbcebf8f27e88896a948b70fbd
|
|
BLAKE2b-256 checksum How to use checksums |
63afd922d97cc47963d431ce6f9869fb9d552bc76cb4a32e6c0d42b8db7a295f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for constspace 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.