recordclass
Mutable variant of namedtuple -- recordclass, which support assignments, compact dataclasses and other memory saving variants.
What it is and what it does
Recordclass is a library for creating lightweight, mutable record types in Python that avoid the memory overhead of standard dataclasses and namedtuples by opting out of cyclic garbage collection. It provides three main interfaces: a `recordclass` factory (namedtuple-like), a `dataobject` base class (dataclass-like), and lightweight container types (`litetuple`, `mutabletuple`) designed for scenarios where you are certain your objects will never participate in reference cycles.
The library is built on a custom metaclass that skips the `PyGC_Head` prefix normally added to Python objects, reducing per-instance memory by 16–32 bytes depending on Python version. This is most useful for applications that create many small, short-lived objects with simple field types (int, float, str, date/time), such as coordinate records, scientific data points, or compact data structures in memory-constrained environments. The trade-off is that you must manually ensure no circular references are created; the library does not enforce this at runtime.
Use it for:
- Store millions of coordinate or vector records (x, y, z) in memory-intensive scientific or graphics applications.
- Build compact data structures for machine learning feature vectors where memory footprint directly impacts cache performance.
- Replace namedtuple in high-throughput data pipelines where object creation speed and size matter.
- Create immutable or mutable tuple-like containers (litetuple, mutabletuple) for collections that will never form cycles.
- Define strongly-typed record classes with type hints that consume less memory than standard dataclass instances.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Recordclass provides memory-efficient, mutable alternatives to namedtuple and dataclass by creating record types that skip Python's garbage collection overhead, reducing instance size by 16–32 bytes depending on Python version.
Yes, if you are building memory-sensitive applications with many small objects and can guarantee no circular references. The active maintenance, permissive license, and support for modern Python versions (3.8–3.14) make it reliable. However, the high install friction (source compilation required) and narrow use case (only beneficial when memory overhead of PyGC_Head is a real bottleneck) mean it is not a general-purpose replacement for dataclass or namedtuple—install only when profiling shows memory is a constraint.
Install
recordclass on PyPI
pip
pip install recordclassuv
uv add recordclasspoetry
poetry add recordclassInstalling recordclass
Before you install
Installation requires compilation from source (high friction). The package is actively maintained with recent commits and supports modern Python versions (3.8–3.14), but the build dependency may complicate deployment in restricted environments.
License in practice
MIT License permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and proprietary projects.
Quickstart
from recordclass import recordclass, dataobject, astuple, asdict
# Factory function
Point = recordclass('Point', 'x y')
p = Point(1, 2)
p.y = -1
print(astuple(p)) # (1, -1)
print(asdict(p)) # {'x': 1, 'y': -1}
# Class-based
class Coord(dataobject):
x: int
y: int
c = Coord(3, 4)
print(c.x, c.y)
Requires a C compiler and Python development headers to build from source; pre-built wheels may not be available for all platforms.
Verify before relying
- Whether pre-built wheels are available for common platforms or if source compilation is always required.
- Actual memory savings in real-world applications compared to dataclass or __slots__ with typical field counts.
- Whether the reference-cycle avoidance guarantee holds under all documented use patterns.
Package facts
| License | The MIT License (MIT) Copyright (c) «2015-2023» «Shibzukhov Zaur, szport at gmail dot com» Permission is hereby granted, free of charge, to any person obtaining a copy of this software - recordclass… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | actively maintained — 221 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 126,365/month — #11,778 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: recordclass-0.24.tar.gz
Keywords: dataclass, namedtuple, recordclass, dataobject
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
namedlistCreates mutable or immutable named tuple-like…
permissive · top 15,000 on PyPI
recordtyperecordtype creates mutable record classes with…
permissive · top 15,000 on PyPI
dataclass-csvReads and writes CSV files using Python…
permissive · top 15,000 on PyPI
tinselGenerates PySpark DataFrame schemas from Python…
permissive · top 15,000 on PyPI
dataclass-factoryConverts dataclasses to and from dictionaries…
permissive · top 15,000 on PyPI
HeapDictHeapDict is a mutable mapping that acts as a…
permissive · top 15,000 on PyPI
ordered-setOrderedSet is a mutable collection that…
permissive · top 1,000 on PyPI
itemadapterItemAdapter wraps data container objects…
permissive · top 5,000 on PyPI
fieldsGenerates lightweight container classes with…
permissive · top 15,000 on PyPI
dataclassesProvides the PEP 557 dataclasses module for…
permissive · top 5,000 on PyPI