skillfed

recordclass

Mutable variant of namedtuple -- recordclass, which support assignments, compact dataclasses and other memory saving variants.

recordclass v0.24 126.4K downloads/30d#11,778 on PyPI37
Permissive 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) Active released

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 recordclass

uv

uv add recordclass

poetry

poetry add recordclass

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: CythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

mutable namedtuplememory-efficient dataclasslightweight record typescompact data structuresgc-free python objectsnamedtuple alternativeslot-like classes
memory-optimizationdata-structuresperformance-tuning

More Python Modules packages