{"id":23344490,"url":"https://github.com/rec/datacls","last_synced_at":"2025-04-10T02:33:22.355Z","repository":{"id":61910213,"uuid":"466758882","full_name":"rec/datacls","owner":"rec","description":"🗂 Take the edge off `dataclass` 🗂","archived":false,"fork":false,"pushed_at":"2024-02-14T14:42:48.000Z","size":662,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-01T19:20:46.759Z","etag":null,"topics":["dataclasses","python","tools"],"latest_commit_sha":null,"homepage":"https://rec.github.io/datacls/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rec.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELIST","contributing":null,"funding":"FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rec"}},"created_at":"2022-03-06T14:19:37.000Z","updated_at":"2023-05-10T20:03:38.000Z","dependencies_parsed_at":"2023-02-18T18:01:01.301Z","dependency_job_id":"bd723f28-8231-48b9-89fa-b29be4d367ff","html_url":"https://github.com/rec/datacls","commit_stats":{"total_commits":57,"total_committers":1,"mean_commits":57.0,"dds":0.0,"last_synced_commit":"fe1d6502589fedb4b4902ad9c3243798be47b1dd"},"previous_names":["rec/dataclass"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rec%2Fdatacls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rec%2Fdatacls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rec%2Fdatacls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rec%2Fdatacls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rec","download_url":"https://codeload.github.com/rec/datacls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144320,"owners_count":21054908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dataclasses","python","tools"],"created_at":"2024-12-21T06:26:46.662Z","updated_at":"2025-04-10T02:33:22.336Z","avatar_url":"https://github.com/rec.png","language":"Python","funding_links":["https://github.com/sponsors/rec"],"categories":[],"sub_categories":[],"readme":"# 🗂 `datacls`: take the edge off `dataclass` 🗂\n\n`dataclasses` is almost perfect.\n\n`datacls` is a tiny, thin wrapper around `dataclass.dataclasses` making it\na bit more self-contained, reflective, and saving a bit of typing.\n\n`datacls` is exactly like `dataclass`, except:\n\n  * Adds three new instance methods: `asdict()`, `astuple()`, `replace()`,\n    and one new class method, `fields()`, all taken from the `dataclasses`\n    module\n\n  * `xmod`-ed for less cruft (so `datacls` is the same as `datacls.dataclass`)\n\n  * The default class is `datacls.immutable` where `frozen=True`.\n\n## Example\n\n    import datacls\n\n    @datacls\n    class One:\n        one: str = 'one'\n        two: int = 2\n        three: dict = datacls.field(dict)\n\n    # `One` has three instance methods: asdict(), astuple(), replace()\n\n    o = One()\n    assert o.asdict() == {'one': 'one', 'two': 2, 'three': {}}\n\n    import dataclasses\n    assert dataclasses.asdict(o) == o.asdict()\n\n    assert o.astuple() == ('one', 2, {})\n\n    o2 = o.replace(one='seven', three={'nine': 9})\n    assert o2 == One('seven', 2, {'nine': 9})\n\n    # `One` has one new class method: fields()\n\n    assert [f.name for f in One.fields()] == ['one', 'two', 'three']\n\n    # @datacls is immutable.\n\n    try:\n        o.one = 'three'\n    except AttributeError:\n        pass\n    else:\n        raise AttributeError('Was mutable!')\n\n    # Usec @datacls.mutable or @datacls(frozen=False)\n    # for mutable classes\n\n    @datacls.mutable\n    class OneMutable:\n        one: str = 'one'\n        two: int = 2\n        three: Dict = datacls.field(dict)\n\n    om = OneMutable()\n    om.one = 'three'\n    assert str(om) == \"OneMutable(one='three', two=2, three={})\"\n\n    # These four new methods won't break your old dataclass by mistake:\n    @datacls\n    class Overloads:\n        one: str = 'one'\n        asdict: int = 1\n        astuple: int = 1\n        fields: int = 1\n        replace: int = 1\n\n    o = Overloads()\n\n    assert ov.one == 'one'\n    assert ov.asdict == 1\n    assert ov.astuple == 1\n    assert ov.fields == 1\n    assert ov.replace == 1\n\n    # You can still access the methods as functions on `datacls`:\n    assert (\n        datacls.asdict(ov) ==\n        {'asdict': 1, 'astuple': 1, 'fields': 1, 'one': 'one', 'replace': 1}\n    )\n\n\n### [API Documentation](https://rec.github.io/datacls#datacls--api-documentation)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frec%2Fdatacls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frec%2Fdatacls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frec%2Fdatacls/lists"}