Miss extension methods from other languages? Python can have those too.
## Installation
```shell
pip install extensified==0.3.0
```
## Usage
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "extensified",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "extensions, extension classes, extension methods",
"author": "Vasiliy Spassky",
"author_email": "spassky99@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/fa/d8/d3b15ff0c89fa8b87edb1d3405cb201d676e7f35303ab66ea268d3df8f51/extensified-0.3.0.tar.gz",
"platform": null,
"description": "Miss extension methods from other languages? Python can have those too.\n\n## Installation\n\n```shell\npip install extensified==0.3.0\n```\n\n## Usage\n\n```python\nfrom dataclasses import dataclass\nfrom datetime import datetime\n\nfrom extensified import extension_on\n\n\n@dataclass\nclass Customer:\n\n name: str\n email: str\n created_at: datetime = datetime.now()\n\n\n@extension_on(Customer)\nclass CustomerStringReprExtension:\n\n @property\n def rfc5322_email(self) -> str:\n return f'{self.name} <{self.email}>'\n\n @property\n def ldap_dn(self) -> str:\n email_domain = self.email.split('@')[1]\n return f'cn={self.name},ou=Users,dc={email_domain.replace(\".\", \",dc=\")}'\n\n @property\n def vcard_name(self) -> str:\n surname = self.name.split()[-1]\n given_names = ' '.join(self.name.split()[:-1])\n return f'FN:{self.name}\\nN:{surname};{given_names};;;'\n\n\ncustomer = Customer(\"John Doe\", \"john@example.com\")\nprint(customer.rfc5322_email)\nprint(customer.ldap_dn)\nprint(customer.vcard_name)\n```\n\n## Limitations\n\n- Make sure that extension class is imported before its methods are used (i.e. import it in your init code).\n- `super()` can't be used in an extension class for now.\n- Type checkers won't understand what's going on and will complain about attributes missing.\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Extension methods for Python.",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/v-spassky/extensified",
"Issues": "https://github.com/v-spassky/extensified/issues",
"Repository": "https://github.com/v-spassky/extensified.git"
},
"split_keywords": [
"extensions",
" extension classes",
" extension methods"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e17bdf244b079d10f94d8a39fc04f6bbfa1d67d52205c863eef606fc732ccc37",
"md5": "9fc654809bcf8c1c0b9db866ed7a99d6",
"sha256": "97d2a695a783ef87e605d69d4ff3d48056c7bb8dcc9c5bf9f6ec999e20f287b6"
},
"downloads": -1,
"filename": "extensified-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9fc654809bcf8c1c0b9db866ed7a99d6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 4045,
"upload_time": "2024-11-20T14:06:21",
"upload_time_iso_8601": "2024-11-20T14:06:21.547952Z",
"url": "https://files.pythonhosted.org/packages/e1/7b/df244b079d10f94d8a39fc04f6bbfa1d67d52205c863eef606fc732ccc37/extensified-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fad8d3b15ff0c89fa8b87edb1d3405cb201d676e7f35303ab66ea268d3df8f51",
"md5": "ccf7cb73a01d4a78a26675a7a4cc847e",
"sha256": "33fd43c01432fd6418f2b01f6d709a18fe4751bf2d3b4d5da3db3acdcb3547f9"
},
"downloads": -1,
"filename": "extensified-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "ccf7cb73a01d4a78a26675a7a4cc847e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 3585,
"upload_time": "2024-11-20T14:06:22",
"upload_time_iso_8601": "2024-11-20T14:06:22.732425Z",
"url": "https://files.pythonhosted.org/packages/fa/d8/d3b15ff0c89fa8b87edb1d3405cb201d676e7f35303ab66ea268d3df8f51/extensified-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-20 14:06:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "v-spassky",
"github_project": "extensified",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "extensified"
}