constantly

Symbolic constants for Python with named text, numeric, and bit-flag values.

Library
PyPI
v23.10.4
24stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
26/100Needs Attention
Development Activity12
Maintenance0
Community20
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture78
Code Quality80
Innovation66
Learning Curve86

constantly is a small, focused Python library that provides symbolic constant support. It lets you define collections of named constants that carry meaningful values — plain symbolic names, numeric values, or bit flags — instead of relying on bare strings or integers scattered through your code.

Originally part of the Twisted project as twisted.python.constants, it was extracted into a standalone package so any project can use it without depending on Twisted. It offers NamedConstant, ValueConstant, and FlagConstant primitives grouped under Names, Values, and Flags containers, giving you readable, self-documenting constants with iteration, comparison, and bitwise flag composition.

What You Get

  • NamedConstant / Names for purely symbolic named constants
  • ValueConstant / Values for constants that carry an associated value
  • FlagConstant / Flags for bitwise-composable flag constants
  • Iteration over a collection’s members and lookup by name or value
  • A tiny, dependency-free package usable outside of Twisted

Common Use Cases

  • Replacing magic strings or integers with self-documenting constants
  • Defining protocol or state enumerations that iterate and compare cleanly
  • Modeling composable bit-flag options with bitwise operators
  • Sharing Twisted-style constants in projects that don’t use Twisted

Under The Hood

Architecture - The library is implemented under constantly/ (primarily _constants.py) around a metaclass-driven container pattern: base container classes (Names, Values, Flags) collect their declared constant members (NamedConstant, ValueConstant, FlagConstant) at class-definition time, assign ordering, and expose iteration and lookup helpers. FlagConstant additionally implements bitwise or/and/xor to combine flags into composite values.

Tech Stack - Pure Python with no runtime dependencies, packaged with a modern pyproject.toml (plus a legacy setup.py) and tested across versions using tox. Documentation is published via Read the Docs.

Code Quality - The code is compact and stable, carrying a test suite under constantly/test and years of production hardening from its origin in Twisted. Its narrow scope keeps the surface easy to reason about and audit.

API Design - The API is declarative and readable: subclass Names/Values/Flags and assign class attributes to constant instances. Members then behave as first-class objects supporting comparison, iteration, and (for flags) bitwise composition, giving enum-like ergonomics with Twisted’s established semantics.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search