René's URL Explorer Experiment


Title: Data Classes in Python (Guide) – Real Python

Open Graph Title: Data Classes in Python (Guide) – Real Python

Description: Learn how a Python dataclass reduces boilerplate, adds type hints and defaults, supports ordering and frozen instances, and still plays well with inheritance.

Open Graph Description: Learn how a Python dataclass reduces boilerplate, adds type hints and defaults, supports ordering and frozen instances, and still plays well with inheritance.

Mail addresses
?subject=Python article for you&body=Data Classes in Python (Guide) on Real Python https://realpython.com/python-data-classes/

Opengraph URL: https://realpython.com/python-data-classes/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Data Classes in Python (Guide)",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/The-Ultimate-Guide-to-Data-Classes-in-Python-3.7_Watermarked.00755fbea935.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-data-classes/",
    "lastReviewed": "2024-03-08",
    "author": {
      "@type": "Person",
      "name": "Geir Arne Hjelle",
      "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
      "url": "https://realpython.com/team/gahjelle/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Dan Bader",
        "image": "https://realpython.com/cdn-cgi/image/width=1000,height=1000,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/daniel-square.d58bf4388750.jpg",
        "url": "https://realpython.com/team/dbader/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Joanna Jablonski",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
        "url": "https://realpython.com/team/jjablonski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Martin Breuss",
        "image": "https://realpython.com/cdn-cgi/image/width=456,height=456,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/martin_breuss_python_square.efb2b07faf9f.jpg",
        "url": "https://realpython.com/team/mbreuss/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2018-05-15T14:00:00+00:00",
  "dateModified": "2024-03-08T09:08:51.615153+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Geir Arne Hjelle",
    "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
    "url": "https://realpython.com/team/gahjelle/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "Learn how a Python dataclass reduces boilerplate, adds type hints and defaults, supports ordering and frozen instances, and still plays well with inheritance."
}

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/The-Ultimate-Guide-to-Data-Classes-in-Python-3.7_Watermarked.00755fbea935.jpg
og:imagehttps://files.realpython.com/media/The-Ultimate-Guide-to-Data-Classes-in-Python-3.7_Watermarked.00755fbea935.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-data-classes/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/python-data-classes/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fpython-data-classes%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/python-data-classes/#toc
Python’s Dataclass in a Nutshellhttps://realpython.com/python-data-classes/#pythons-dataclass-in-a-nutshell
Alternatives to Data Classeshttps://realpython.com/python-data-classes/#alternatives-to-data-classes
Basic Data Classeshttps://realpython.com/python-data-classes/#basic-data-classes
Default Valueshttps://realpython.com/python-data-classes/#default-values
Type Hintshttps://realpython.com/python-data-classes/#type-hints
Adding Methodshttps://realpython.com/python-data-classes/#adding-methods
More Flexible Data Classeshttps://realpython.com/python-data-classes/#more-flexible-data-classes
Advanced Default Valueshttps://realpython.com/python-data-classes/#advanced-default-values
You Need Representation?https://realpython.com/python-data-classes/#you-need-representation
Comparing Cardshttps://realpython.com/python-data-classes/#comparing-cards
Immutable Data Classeshttps://realpython.com/python-data-classes/#immutable-data-classes
Inheritancehttps://realpython.com/python-data-classes/#inheritance
Optimizing Data Classeshttps://realpython.com/python-data-classes/#optimizing-data-classes
Conclusion & Further Readinghttps://realpython.com/python-data-classes/#conclusion-further-reading
https://realpython.com/feedback/survey/article/python-data-classes/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-data-classes/disliked/?from=article-sidebar
Using Data Classes in Pythonhttps://realpython.com/courses/python-data-classes/
Geir Arne Hjellehttps://realpython.com/python-data-classes/#author
https://realpython.com/python-data-classes/#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
Python’s Dataclass in a Nutshellhttps://realpython.com/python-data-classes/#pythons-dataclass-in-a-nutshell
Alternatives to Data Classeshttps://realpython.com/python-data-classes/#alternatives-to-data-classes
Basic Data Classeshttps://realpython.com/python-data-classes/#basic-data-classes
Default Valueshttps://realpython.com/python-data-classes/#default-values
Type Hintshttps://realpython.com/python-data-classes/#type-hints
Adding Methodshttps://realpython.com/python-data-classes/#adding-methods
More Flexible Data Classeshttps://realpython.com/python-data-classes/#more-flexible-data-classes
Advanced Default Valueshttps://realpython.com/python-data-classes/#advanced-default-values
You Need Representation?https://realpython.com/python-data-classes/#you-need-representation
Comparing Cardshttps://realpython.com/python-data-classes/#comparing-cards
Immutable Data Classeshttps://realpython.com/python-data-classes/#immutable-data-classes
Inheritancehttps://realpython.com/python-data-classes/#inheritance
Optimizing Data Classeshttps://realpython.com/python-data-classes/#optimizing-data-classes
Conclusion & Further Readinghttps://realpython.com/python-data-classes/#conclusion-further-reading
Remove adshttps://realpython.com/account/join/
Using Data Classes in Pythonhttps://realpython.com/courses/python-data-classes/
Get a sample chapter from Python Tricks: The Bookhttps://realpython.com/bonus/python-tricks-sample-pdf/
https://realpython.com/quizzes/python-data-classes/
Data Classes in Pythonhttps://realpython.com/quizzes/python-data-classes/
https://realpython.com/python-data-classes/#pythons-dataclass-in-a-nutshell
Python 3.7https://realpython.com/python37-new-features/
decoratorhttps://realpython.com/primer-on-python-decorators/
.__repr__() methodhttps://realpython.com/operator-function-overloading/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-data-classes/#alternatives-to-data-classes
a tuple or a dicthttps://dbader.org/blog/records-structs-and-data-transfer-objects-in-python
variablehttps://realpython.com/python-variables/
namedtuplehttps://realpython.com/python-namedtuple/
immutablehttps://realpython.com/python-mutable-vs-immutable-types/
inspirations for data classeshttps://mail.python.org/pipermail/python-dev/2017-December/151034.html
attrs projecthttp://www.attrs.org
dependencyhttps://realpython.com/courses/managing-python-dependencies/
many other similar projectshttps://www.python.org/dev/peps/pep-0557/#rationale
typing.NamedTuplehttps://docs.python.org/library/typing.html#typing.NamedTuple
namedlisthttps://pypi.org/project/namedlist/
attrdicthttps://pypi.org/project/attrdict/
plumberhttps://pypi.org/project/plumber/
fieldshttps://pypi.org/project/fields/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-data-classes/#basic-data-classes
@dataclass decoratorhttps://realpython.com/primer-on-python-decorators/
variable annotationshttps://www.python.org/dev/peps/pep-0526/
soonhttps://realpython.com/python-data-classes/#type-hints
Python classhttps://realpython.com/python-classes/
data model methodshttps://docs.python.org/reference/datamodel.html#basic-customization
https://realpython.com/python-data-classes/#default-values
Laterhttps://realpython.com/python-data-classes/#advanced-default-values
https://realpython.com/python-data-classes/#type-hints
typinghttps://realpython.com/python-type-checking/
text stringhttps://realpython.com/python-strings/
Python is and will always be a dynamically typed languagehttps://www.python.org/dev/peps/pep-0484/#non-goals
Mypyhttp://mypy-lang.org
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-data-classes/#adding-methods
the haversine formulahttps://en.wikipedia.org/wiki/Haversine_formula
https://files.realpython.com/media/haversine_formula_150.fb2b87d122a4.png
https://realpython.com/python-data-classes/#more-flexible-data-classes
https://realpython.com/python-data-classes/#advanced-default-values
regular (French) deckhttps://en.wikipedia.org/wiki/French_playing_cards
listhttps://realpython.com/python-lists-tuples/
Unicode symbolshttps://en.wikipedia.org/wiki/Playing_cards_in_Unicode
Python supports writing source code in UTF-8 by defaulthttps://docs.python.org/howto/unicode.html#unicode-literals-in-python-source-code
this page on Unicode inputhttps://en.wikipedia.org/wiki/Unicode_input
using mutable default argumentshttp://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments
prevent you from doing thishttps://www.python.org/dev/peps/pep-0557/#mutable-default-values
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-data-classes/#you-need-representation
two different string representationshttps://dbader.org/blog/python-repr-vs-str
Practicality beats purityhttps://www.python.org/dev/peps/pep-0020/
https://realpython.com/python-data-classes/#comparing-cards
the original PEPhttps://www.python.org/dev/peps/pep-0557/#id7
special methodhttps://realpython.com/python-classes/#special-methods-and-protocols
sortinghttps://realpython.com/sorting-algorithms-python/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-data-classes/#immutable-data-classes
immutablehttps://medium.com/@meghamohan/mutable-and-immutable-side-of-python-c2145cf72747
you saw earlierhttps://realpython.com/python-data-classes/#basic-data-classes
this video for further infohttps://www.youtube.com/watch?v=p9ppfvHv2Us
https://realpython.com/python-data-classes/#inheritance
subclasshttps://realpython.com/python3-object-oriented-programming/
If a parameter has a default value, all following parameters must also have a default valuehttps://docs.python.org/reference/compound_stmts.html#function-definitions
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-data-classes/#optimizing-data-classes
slotshttps://docs.python.org/reference/datamodel.html#slots
Pymplerhttps://pythonhosted.org/Pympler/
timeithttps://docs.python.org/library/timeit.html
https://realpython.com/python-data-classes/#conclusion-further-reading
PEP 557https://www.python.org/dev/peps/pep-0557/
GitHub repohttps://github.com/ericvsmith/dataclasses/issues?utf8=%E2%9C%93&q=
Dataclasses: The code generator to end all code generatorshttps://www.youtube.com/watch?v=T-TwcmT6Rcw
https://realpython.com/quizzes/python-data-classes/
Data Classes in Pythonhttps://realpython.com/quizzes/python-data-classes/
https://realpython.com/feedback/survey/article/python-data-classes/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-data-classes/disliked/?from=article-footer
Using Data Classes in Pythonhttps://realpython.com/courses/python-data-classes/
https://realpython.com/team/gahjelle/
» More about Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/dbader/
Danhttps://realpython.com/team/dbader/
https://realpython.com/team/jjablonski/
Joannahttps://realpython.com/team/jjablonski/
https://realpython.com/team/mbreuss/
Martinhttps://realpython.com/team/mbreuss/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-data-classes
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-data-classes
https://realpython.com/feedback/survey/article/python-data-classes/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-data-classes/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-data-classes%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Data%20Classes%20in%20Python%20%28Guide%29&url=https%3A%2F%2Frealpython.com%2Fpython-data-classes%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Data%20Classes%20in%20Python%20%28Guide%29%20https%3A%2F%2Frealpython.com%2Fpython-data-classes%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-data-classes%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
Using Data Classes in Pythonhttps://realpython.com/courses/python-data-classes/
Python Classes: The Power of Object-Oriented Programminghttps://realpython.com/python-classes/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-data-classes
Primer on Python Decoratorshttps://realpython.com/primer-on-python-decorators/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-data-classes
Python Type Checking (Guide)https://realpython.com/python-type-checking/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-data-classes
Logging in Pythonhttps://realpython.com/python-logging/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-data-classes
Build Enumerations of Constants With Python's Enumhttps://realpython.com/python-enum/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-data-classes
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-data-classes%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-data-classes%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-data-classes/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.