Registry / data / recordclass

recordclass

JSON →
library0.24pypypi✓ verified 35d ago

recordclass is a Python library that provides mutable variants of `collections.namedtuple`, supporting assignments and offering memory-saving alternatives like `dataobject` and `structclass`. These types aim for high performance and reduced memory footprint by optionally disabling cyclic garbage collection and removing instance dictionaries. Currently at version 0.24, the library is actively maintained with releases supporting the latest Python versions, including 3.14, and aims to be a fast, memory-efficient, and flexible choice for data representation.

dataserialization
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

For creating mutable namedtuple-like classes.

from recordclass import recordclass

For creating compact dataclass-like objects with memory optimizations.

from recordclass import dataobject

Factory function to create dataobject-based classes, similar to standard dataclasses.make_dataclass.

from recordclass import make_dataclass

Decorator for def-style declarations of dataobject-based classes that behave like structs.

from recordclass import as_record

The base type for recordclass instances; less commonly directly instantiated by users.

from recordclass import mutabletuple

This quickstart demonstrates how to create mutable record-like objects using `recordclass`, `dataobject` (similar to dataclasses), `make_dataclass`, and the `as_record` decorator. It highlights the mutability aspect and attribute access.

from recordclass import recordclass, dataobject, make_dataclass, as_record import os # Using recordclass (mutable namedtuple-like) Point = recordclass('Point', 'x y') p = Point(1, 2) print(f"Initial Point: {p}") p.x = 10 print(f"Modified Point: {p}") # Using dataobject (compact dataclass-like) class ColorPoint(dataobject): x: int y: int color: str = 'red' cp = ColorPoint(1, 2) print(f"ColorPoint: {cp}") cp.color = 'blue' print(f"Modified ColorPoint: {cp}") # Using make_dataclass User = make_dataclass("User", [("name", str), ("age", int)]) u = User("Alice", 30) print(f"User: {u}") # Using as_record decorator @as_record() def Product(name: str, price: float, sku=None): pass prod = Product("Laptop", 1200.0, "LAP001") print(f"Product: {prod}")
Debug
Known footguns
gotchaMutable Default Values: When defining `dataobject` classes with mutable default values (e.g., lists, dicts), the default object is shared across all instances. This is a common Python pitfall. Use `copy_default=True` or `recordclass.Factory` for independent defaults.
breakingAttribute Deletion Not Allowed: Attempting to delete an attribute using `del instance.attribute` will raise an `AttributeError`. This was explicitly disallowed for `dataobject`-based classes in recent versions to maintain internal structure.
gotchaNo `__dict__` by Default in `dataobject`: `dataobject`-based classes do not have an instance `__dict__` or `__weakref__` by default for memory optimization. This means you cannot add new attributes to instances after creation, which can lead to `AttributeError`.
breakingPython Version Compatibility (older versions): Older versions of `recordclass` (e.g., <0.24) had known build and runtime issues with newer Python interpreters (e.g., Python 3.9, 3.12, 3.14) due to internal C API changes. This often manifested as build errors during `pip install`.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
23 hits · last 30 days
gptbot
4
bytedance
4
ahrefsbot
3
script
1
bingbot
1
mj12bot
1
googlebot
1
Resources