METADATA 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Metadata-Version: 2.4
  2. Name: attrs
  3. Version: 26.1.0
  4. Summary: Classes Without Boilerplate
  5. Project-URL: Documentation, https://www.attrs.org/
  6. Project-URL: Changelog, https://www.attrs.org/en/stable/changelog.html
  7. Project-URL: GitHub, https://github.com/python-attrs/attrs
  8. Project-URL: Funding, https://github.com/sponsors/hynek
  9. Project-URL: Tidelift, https://tidelift.com/subscription/pkg/pypi-attrs?utm_source=pypi-attrs&utm_medium=pypi
  10. Author-email: Hynek Schlawack <hs@ox.cx>
  11. License-Expression: MIT
  12. License-File: LICENSE
  13. Keywords: attribute,boilerplate,class
  14. Classifier: Development Status :: 5 - Production/Stable
  15. Classifier: Programming Language :: Python :: 3.9
  16. Classifier: Programming Language :: Python :: 3.10
  17. Classifier: Programming Language :: Python :: 3.11
  18. Classifier: Programming Language :: Python :: 3.12
  19. Classifier: Programming Language :: Python :: 3.13
  20. Classifier: Programming Language :: Python :: 3.14
  21. Classifier: Programming Language :: Python :: Implementation :: CPython
  22. Classifier: Programming Language :: Python :: Implementation :: PyPy
  23. Classifier: Typing :: Typed
  24. Requires-Python: >=3.9
  25. Description-Content-Type: text/markdown
  26. <p align="center">
  27. <a href="https://www.attrs.org/">
  28. <img src="https://raw.githubusercontent.com/python-attrs/attrs/main/docs/_static/attrs_logo.svg" width="35%" alt="attrs" />
  29. </a>
  30. </p>
  31. *attrs* is the Python package that will bring back the **joy** of **writing classes** by relieving you from the drudgery of implementing object protocols (aka [dunder methods](https://www.attrs.org/en/latest/glossary.html#term-dunder-methods)).
  32. Trusted by NASA for [Mars missions since 2020](https://github.com/readme/featured/nasa-ingenuity-helicopter)!
  33. Its main goal is to help you to write **concise** and **correct** software without slowing down your code.
  34. ## Sponsors
  35. *attrs* would not be possible without our [amazing sponsors](https://github.com/sponsors/hynek).
  36. Especially those generously supporting us at the *The Organization* tier and higher:
  37. <!-- sponsor-break-begin -->
  38. <p align="center">
  39. <!-- [[[cog
  40. import pathlib, tomllib
  41. for sponsor in tomllib.loads(pathlib.Path("pyproject.toml").read_text())["tool"]["sponcon"]["sponsors"]:
  42. print(f'<a href="{sponsor["url"]}"><img title="{sponsor["title"]}" src="https://www.attrs.org/en/26.1.0/_static/sponsors/{sponsor["img"]}" width="190" /></a>')
  43. ]]] -->
  44. <a href="https://www.variomedia.de/"><img title="Variomedia AG" src="https://www.attrs.org/en/26.1.0/_static/sponsors/Variomedia.svg" width="190" /></a>
  45. <a href="https://tidelift.com/?utm_source=lifter&utm_medium=referral&utm_campaign=hynek"><img title="Tidelift" src="https://www.attrs.org/en/26.1.0/_static/sponsors/Tidelift.svg" width="190" /></a>
  46. <a href="https://kraken.tech/"><img title="Kraken Tech" src="https://www.attrs.org/en/26.1.0/_static/sponsors/Kraken.svg" width="190" /></a>
  47. <a href="https://privacy-solutions.org/"><img title="Privacy Solutions" src="https://www.attrs.org/en/26.1.0/_static/sponsors/Privacy-Solutions.svg" width="190" /></a>
  48. <a href="https://filepreviews.io/"><img title="FilePreviews" src="https://www.attrs.org/en/26.1.0/_static/sponsors/FilePreviews.svg" width="190" /></a>
  49. <a href="https://www.testmuai.com/?utm_medium=sponsor&utm_source=structlog"><img title="TestMu AI" src="https://www.attrs.org/en/26.1.0/_static/sponsors/TestMu-AI.svg" width="190" /></a>
  50. <a href="https://polar.sh/"><img title="Polar" src="https://www.attrs.org/en/26.1.0/_static/sponsors/Polar.svg" width="190" /></a>
  51. <!-- [[[end]]] -->
  52. </p>
  53. <!-- sponsor-break-end -->
  54. <p align="center">
  55. <strong>Please consider <a href="https://github.com/sponsors/hynek">joining them</a> to help make <em>attrs</em>’s maintenance more sustainable!</strong>
  56. </p>
  57. <!-- teaser-end -->
  58. ## Example
  59. *attrs* gives you a class decorator and a way to declaratively define the attributes on that class:
  60. <!-- code-begin -->
  61. ```pycon
  62. >>> from attrs import asdict, define, make_class, Factory
  63. >>> @define
  64. ... class SomeClass:
  65. ... a_number: int = 42
  66. ... list_of_numbers: list[int] = Factory(list)
  67. ...
  68. ... def hard_math(self, another_number):
  69. ... return self.a_number + sum(self.list_of_numbers) * another_number
  70. >>> sc = SomeClass(1, [1, 2, 3])
  71. >>> sc
  72. SomeClass(a_number=1, list_of_numbers=[1, 2, 3])
  73. >>> sc.hard_math(3)
  74. 19
  75. >>> sc == SomeClass(1, [1, 2, 3])
  76. True
  77. >>> sc != SomeClass(2, [3, 2, 1])
  78. True
  79. >>> asdict(sc)
  80. {'a_number': 1, 'list_of_numbers': [1, 2, 3]}
  81. >>> SomeClass()
  82. SomeClass(a_number=42, list_of_numbers=[])
  83. >>> C = make_class("C", ["a", "b"])
  84. >>> C("foo", "bar")
  85. C(a='foo', b='bar')
  86. ```
  87. After *declaring* your attributes, *attrs* gives you:
  88. - a concise and explicit overview of the class's attributes,
  89. - a nice human-readable `__repr__`,
  90. - equality-checking methods,
  91. - an initializer,
  92. - and much more,
  93. *without* writing dull boilerplate code again and again and *without* runtime performance penalties.
  94. ---
  95. This example uses *attrs*'s modern APIs that have been introduced in version 20.1.0, and the *attrs* package import name that has been added in version 21.3.0.
  96. The classic APIs (`@attr.s`, `attr.ib`, plus their serious-business aliases) and the `attr` package import name will remain **indefinitely**.
  97. Check out [*On The Core API Names*](https://www.attrs.org/en/latest/names.html) for an in-depth explanation!
  98. ### Hate Type Annotations!?
  99. No problem!
  100. Types are entirely **optional** with *attrs*.
  101. Simply assign `attrs.field()` to the attributes instead of annotating them with types:
  102. ```python
  103. from attrs import define, field
  104. @define
  105. class SomeClass:
  106. a_number = field(default=42)
  107. list_of_numbers = field(factory=list)
  108. ```
  109. ## Data Classes
  110. On the tin, *attrs* might remind you of `dataclasses` (and indeed, `dataclasses` [are a descendant](https://hynek.me/articles/import-attrs/) of *attrs*).
  111. In practice it does a lot more and is more flexible.
  112. For instance, it allows you to define [special handling of NumPy arrays for equality checks](https://www.attrs.org/en/stable/comparison.html#customization), allows more ways to [plug into the initialization process](https://www.attrs.org/en/stable/init.html#hooking-yourself-into-initialization), has a replacement for `__init_subclass__`, and allows for stepping through the generated methods using a debugger.
  113. For more details, please refer to our [comparison page](https://www.attrs.org/en/stable/why.html#data-classes), but generally speaking, we are more likely to commit crimes against nature to make things work that one would expect to work, but that are quite complicated in practice.
  114. ## Project Information
  115. - [**Changelog**](https://www.attrs.org/en/stable/changelog.html)
  116. - [**Documentation**](https://www.attrs.org/)
  117. - [**PyPI**](https://pypi.org/project/attrs/)
  118. - [**Source Code**](https://github.com/python-attrs/attrs)
  119. - [**Contributing**](https://github.com/python-attrs/attrs/blob/main/.github/CONTRIBUTING.md)
  120. - [**Third-party Extensions**](https://github.com/python-attrs/attrs/wiki/Extensions-to-attrs)
  121. - **Get Help**: use the `python-attrs` tag on [Stack Overflow](https://stackoverflow.com/questions/tagged/python-attrs)
  122. ### *attrs* for Enterprise
  123. Available as part of the [Tidelift Subscription](https://tidelift.com/?utm_source=lifter&utm_medium=referral&utm_campaign=hynek).
  124. The maintainers of *attrs* and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications.
  125. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
  126. ## Release Information
  127. ### Backwards-incompatible Changes
  128. - Field aliases are now resolved *before* calling `field_transformer`, so transformers receive fully populated `Attribute` objects with usable `alias` values instead of `None`.
  129. The new `Attribute.alias_is_default` flag indicates whether the alias was auto-generated (`True`) or explicitly set by the user (`False`).
  130. [#1509](https://github.com/python-attrs/attrs/issues/1509)
  131. ### Changes
  132. - Fix type annotations for `attrs.validators.optional()`, so it no longer rejects tuples with more than one validator.
  133. [#1496](https://github.com/python-attrs/attrs/issues/1496)
  134. - The `attrs.validators.disabled()` contextmanager can now be nested.
  135. [#1513](https://github.com/python-attrs/attrs/issues/1513)
  136. - Frozen classes can set `on_setattr=attrs.setters.NO_OP` in addition to `None`.
  137. [#1515](https://github.com/python-attrs/attrs/issues/1515)
  138. - It's now possible to pass *attrs* **instances** in addition to *attrs* **classes** to `attrs.fields()`.
  139. [#1529](https://github.com/python-attrs/attrs/issues/1529)
  140. ---
  141. [Full changelog →](https://www.attrs.org/en/stable/changelog.html)