Skip to main content

fieldz

License PyPI Python Version CI codecov

Unified API for working with multiple dataclass-like libraries

Dataclass patterns

There are many libraries that implement a similar dataclass-like pattern!

dataclasses.dataclass

import dataclasses

@dataclasses.dataclass
class SomeDataclass:
    a: int = 0
    b: str = "b"
    c: list[int] = dataclasses.field(default_factory=list)

pydantic.BaseModel

import pydantic

class SomePydanticModel(pydantic.BaseModel):
    a: int = 0
    b: str = "b"
    c: list[int] = pydantic.Field(default_factory=list)

attrs.define

import attrs

@attrs.define
class SomeAttrsModel:
    a: int = 0
    b: str = "b"
    c: list[int] = attrs.field(factory=list)

msgspec.Struct

import msgspec

class SomeMsgspecStruct(msgspec.Struct):
    a: int = 0
    b: str = "b"
    c: list[int] = msgspec.field(default_factory=list)

etc...

Unified API

These are all awesome libraries, and each has its own strengths and weaknesses. Sometimes, however, you just want to be able to query basic information about a dataclass-like object, such as getting field names or types, or converting it to a dictionary.

fieldz provides a unified API for these operations (following or extending the API from dataclasses when possible).

def fields(obj: Any) -> tuple[Field, ...]:
    """Return a tuple of fieldz.Field objects for the object."""

def replace(obj: Any, /, **changes: Any) -> Any:
    """Return a copy of obj with the specified changes."""

def asdict(obj: Any) -> dict[str, Any]:
    """Return a dict representation of obj."""

def astuple(obj: Any) -> tuple[Any, ...]:
    """Return a tuple representation of obj."""

def params(obj: Any) -> DataclassParams:
    """Return parameters used to define the dataclass."""

The fieldz.Field and fieldz.DataclassParam objects are simple dataclasses that match the protocols of dataclasses.Field and the (private) dataclasses._DataclassParams objects, respectively. The field object also adds a native_field attribute that is the original field object from the underlying library.

Example

from fieldz import Field, fields

standardized_fields = (
    Field(name="a", type=int, default=0),
    Field(name="b", type=str, default="b"),
    Field(name="c", type=list[int], default_factory=list),
)

assert (
    fields(SomeDataclass)
    == fields(SomePydanticModel)
    == fields(SomeAttrsModel)
    == fields(SomeMsgspecStruct)
    == standardized_fields
)

Supported libraries

... maybe someday?

Metadata

Release files for fieldz 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fieldz 0.2.0
File Size Uploaded
fieldz-0.2.0.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fieldz 0.2.0
File Interpreter ABI Platform
fieldz-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.2 kB

Release files / fieldz-0.2.0.tar.gz

Download URL fieldz-0.2.0.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e11215188cad5c5371113d2b7707155960efd0d48500b6bf675648bc3f6fc8d6
BLAKE2b-256 checksum
How to use checksums
f8467a8d1db959eabd5d3e52bd3c000a8b132184b7651cbd5481c4cbf31ff65d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 24, 2026.

Transparency log

Release files / fieldz-0.2.0-py3-none-any.whl

Download URL fieldz-0.2.0-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43b5be702816df39f55d08ae392eaabe58d3c69d2e4b61a853252cb2da41931f
BLAKE2b-256 checksum
How to use checksums
fe9d9034acaf3d80e85deb3d49876cb734479327b9cf89a918815ef67cb6b36c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page