Registry / data / recordclass

recordclass

JSON →
library0.24pypypi✓ verified 88d 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.

pip install recordclass
INSTALL
IMPORT
SIG · RECORDCLASS
R
recordclass
datapythonv0.24
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
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.10–3.920 runs
build_error
glibc
py 3.10–3.920 runs
build_error
Code
Verified usage

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

recordclass
✓ from recordclass import recordclass
For creating mutable namedtuple-like classes.
dataobject
✓ from recordclass import dataobject
For creating compact dataclass-like objects with memory optimizations.
make_dataclass
✓ from recordclass import make_dataclass
Factory function to create dataobject-based classes, similar to standard dataclasses.make_dataclass.
as_record
✓ from recordclass import as_record
Decorator for def-style declarations of dataobject-based classes that behave like structs.
mutabletuple
✓ from recordclass import mutabletuple
The base type for recordclass instances; less commonly directly instantiated by users.

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 issues
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.
fix
Use `class MyData(dataobject, copy_default=True): my_list: list = []` or `from recordclass import Factory; class MyData(dataobject): my_list: list = Factory(list)`.
affects: All versions
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.
fix
Instead of `del p.x`, assign `p.x = None` or use a method to clear/reset the field if available and semantically appropriate.
affects: 0.24 and newer
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`.
fix
Define all required fields in the class definition. If dynamic attributes are strictly needed, consider `collections.namedtuple` (immutable), `dataclasses` (mutable with `__dict__`), or re-evaluating the use case. You can enable GC and `__dict__` if necessary via decorators or factory functions for specific classes, but this negates the memory benefits.
affects: All versions (since introduction of dataobject)
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`.
fix
Upgrade to the latest `recordclass` version (0.24 or newer), which explicitly adds support for Python 3.14 and earlier versions.
affects: Prior to 0.24 (e.g., 0.14.0, 0.22.0.2 with Python 3.12/3.14)
Errors
Common errors & fixes
TypeError: 'X' object is not callable
This usually occurs when you shadow a class name with an instance of that class, then try to call the instance as if it were the class itself to create a new object. For example, `Point = recordclass(...)`, then `point = Point(...)`, and later `point = point(...)`.
fix
Ensure distinct variable names for classes and instances (e.g., `PointClass` and `point_instance`) or be careful about scope. A common Python convention is to capitalize class names: `Point = recordclass(...)`, then `point = Point(...)`.
AttributeError: 'X' object has no attribute 'Y' and no __dict__ for setting new attributes
You are attempting to assign a new attribute (`Y`) to an instance of a `dataobject`-based class (`X`) that was not defined in the class's fields. These classes omit `__dict__` for memory efficiency, preventing dynamic attribute assignment.
fix
Define all necessary attributes as fields in the `dataobject` class definition. If truly dynamic attributes are needed, `recordclass` may not be the ideal choice for that specific data structure.
TypeError: the number of the arguments greater than the number of fields
This error occurs during instance creation when too many arguments (either positional or keyword) are provided compared to the fields defined in the `recordclass` or `dataobject` type. It can also happen in subclasses with custom `__init__` methods if argument handling is incorrect.
fix
Review the class definition and the arguments passed during instantiation. Ensure that the number and names of arguments match the defined fields, accounting for default values. If using `__init__` in a subclass, ensure it correctly calls the superclass's initializer and handles its arguments.
Building wheel for recordclass (setup.py) ... error
This build error typically indicates problems compiling the C extensions of `recordclass`. Common causes include missing C build tools, incompatible Python development headers, or, historically, `recordclass` versions not yet supporting newer Python releases due to C API changes.
fix
Ensure you have C/C++ build tools installed (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, Visual C++ Build Tools on Windows). Upgrade `recordclass` to the latest version (0.24) as it includes fixes for newer Python versions.
Upgrade
Version history
0.24latest on PyPI · released Jan 5, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
recordclass — pip install recordclass · libregistry