Miss extension methods from other languages? Python can have those too.
Installation
pip install extensified==0.3.0
Usage
from dataclasses import dataclass
from datetime import datetime
from extensified import extension_on
@dataclass
class Customer:
name: str
email: str
created_at: datetime = datetime.now()
@extension_on(Customer)
class CustomerStringReprExtension:
@property
def rfc5322_email(self) -> str:
return f'{self.name} <{self.email}>'
@property
def ldap_dn(self) -> str:
email_domain = self.email.split('@')[1]
return f'cn={self.name},ou=Users,dc={email_domain.replace(".", ",dc=")}'
@property
def vcard_name(self) -> str:
surname = self.name.split()[-1]
given_names = ' '.join(self.name.split()[:-1])
return f'FN:{self.name}\nN:{surname};{given_names};;;'
customer = Customer("John Doe", "john@example.com")
print(customer.rfc5322_email)
print(customer.ldap_dn)
print(customer.vcard_name)
Limitations
- Make sure that extension class is imported before its methods are used (i.e. import it in your init code).
super()can't be used in an extension class for now.- Type checkers won't understand what's going on and will complain about attributes missing.
Metadata
Release files for extensified 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| extensified-0.3.0.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| extensified-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / extensified-0.3.0.tar.gz
| Download URL | extensified-0.3.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33fd43c01432fd6418f2b01f6d709a18fe4751bf2d3b4d5da3db3acdcb3547f9
|
|
BLAKE2b-256 checksum How to use checksums |
fad8d3b15ff0c89fa8b87edb1d3405cb201d676e7f35303ab66ea268d3df8f51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / extensified-0.3.0-py3-none-any.whl
| Download URL | extensified-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97d2a695a783ef87e605d69d4ff3d48056c7bb8dcc9c5bf9f6ec999e20f287b6
|
|
BLAKE2b-256 checksum How to use checksums |
e17bdf244b079d10f94d8a39fc04f6bbfa1d67d52205c863eef606fc732ccc37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|