Skip to main content

dictclasses

A simple yet powerful decorator to create custom classes with dict-like behavior.

Installation

pip install dictclasses

Description

dictclasses provides the @dictclass decorator that transforms any Python class into a dict-like object. The decorated class accepts a dictionary as its first argument and exposes all standard dictionary methods (keys, values, items, get, pop, update, etc.) while allowing you to define custom methods and properties.

Usage

Basic usage

from dictclasses import dictclass

@dictclass
class Person:
    @property
    def full_name(self):
        return f"{self['first_name']} {self['last_name']}"

person = Person({"first_name": "John", "last_name": "Doe"})
print(person["first_name"])  # John
print(person.full_name)      # John Doe
print(person.keys())         # dict_keys(['first_name', 'last_name'])

From JSON / HJSON files

@dictclass
class Config:
    pass

config = Config.from_json("config.json")
# or
config = Config.from_hjson("config.hjson")

Available methods

The decorator adds the following dict methods (unless already defined in the class):

  • __getitem__, __setitem__
  • __len__, __iter__
  • keys, values, items
  • get, pop, popitem
  • copy, deepcopy
  • update, clear, setdefault
  • fromkeys
  • from_json, from_hjson (class methods)

Metadata

Release files for dictclasses 1.0.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 dictclasses 1.0.0
File Size Uploaded Provenance Actions
dictclasses-1.0.0.tar.gz 2.7 kB Without provenance Details for dictclasses-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 5.4 kB

Release files / dictclasses-1.0.0.tar.gz

Download URL dictclasses-1.0.0.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ef7a2febf2916fd2533833a890ac3f1f2bb21b671b5ddb0c20b8ad9a7f535646
BLAKE2b-256 checksum
How to use checksums
6c92c3da2694c62e77481f881ab7bdc2054de30d8869915eed0a3c09fe56a854
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / dictclasses-1.0.0-py3-none-any.whl

Download URL dictclasses-1.0.0-py3-none-any.whl
Size 2.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1ff0a29ced43d73e94fb2d4c9969e7c7a904abc8655d1f9c4b48a06d035e766
BLAKE2b-256 checksum
How to use checksums
561548145f3bc425d35658e8d31f50fed5b86f8017f88e80cfd5c23ca9169508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for dictclasses 1.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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