pyAttributes
The Python package pyAttributes offers implementations of .NET-like attributes
realized with Python decorators. The package also offers a mixin-class to ease
using classes having annotated methods.
In addition, an ArgParseAttributes module is provided, which allows users to
describe complex argparse command-line argument parser structures in a declarative
way.
Attributes can create a complex class hierarchy. This helps in finding and filtering for annotated properties and user-defined data. These search operations can be called globally on the attribute classes or locally within an annotated class. Therefore the provided helper-mixin should be inherited.
Use Cases
Annotate properties and user-defined data to methods.
Derived use cases:
- Describe a command line argument parser (argparse).
See pyAttributes Documentation -> ArgParse Examples - Mark class members for documentation.
See SphinxExtensions -> DocumentMemberAttribute
Planned implementations:
- Annotate user-defined data to classes.
- Describe test cases and test suits to get a cleaner syntax for Python's unit tests.
Technique
The annotated data is stored in an additional __dict__ entry for each
annotated method. By default, the entry is called __pyattr__. Multiple
attributes can be applied to the same method.
Creating new Attributes
Simple User-Defined Attribute
class SimpleAttribute(Attribute):
pass
User-Defined Attribute with Data
class DataAttribute(Attribute):
data: str = None
def __init__(self, data:str):
self.data = data
@property
def Data(self):
return self.data
Applying Attributes to Methods
class ProgramWithHelper(AttributeHelperMixin):
@SimpleAttribute()
def Method_1(self):
"""This method is marked as simple."""
@DataAttribute("hello world")
def Method_2(self):
"""This method as annotated data."""
Finding Methods with Attributes
Finding Methods with Global Search
methods = SimpleAttribute.GetMethods()
for method, attributes in methods.items():
print(method)
for attribute in attributes:
print(" ", attribute)
Finding Methods with Class-Wide Search
class ProgramWithHelper(AttributeHelperMixin):
@SimpleAttribute()
def Method_1(self):
"""This method is marked as simple."""
@DataAttribute("hello world")
def Method_2(self):
"""This method as annotated data."""
def test_GetMethods(self):
methods = self.GetMethods(filter=DataAttribute)
for method, attributes in methods.items():
print(method)
for attribute in attributes:
print(" ", attribute)
def test_GetAttributes(self):
attributes = self.GetAttributes(self.Method_1)
for attribute in attributes:
print(" ", attribute)
Contributors
- Patrick Lehmann (Maintainer)
- and more...
License
This Python package (source code) licensed under Apache License 2.0.
The accompanying documentation is licensed under Creative Commons - Attribution 4.0 (CC-BY 4.0).
SPDX-License-Identifier: Apache-2.0
Metadata
Release files for pyAttributes 2.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyAttributes-2.5.1.tar.gz | 14.4 kB | Without provenance | Details for pyAttributes-2.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyAttributes-2.5.1-py3-none-any.whl | Python 3 | none | any | Details for pyAttributes-2.5.1-py3-none-any.whl |
Total release size: 27.9 kB
Release files / pyAttributes-2.5.1.tar.gz
| Download URL | pyAttributes-2.5.1.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f47d2c862df129e15b02ffb7efb3929e946435e69e567f09199b1d80b63759d
|
|
BLAKE2b-256 checksum How to use checksums |
81e76171db8acd68eec0715ac622bd5999ec6c64f56ee1d6b40dcfc038d79c0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Release files / pyAttributes-2.5.1-py3-none-any.whl
| Download URL | pyAttributes-2.5.1-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15e04d85353ab38dfdfa40940e3a3386c0d394e9900d8b41f7d04587d429b83a
|
|
BLAKE2b-256 checksum How to use checksums |
65ae025111432a6198c0d5bcd6993e0f2b59dd10140afaa8a28de1d4db3d9c45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Security for pyAttributes 2.5.1
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.