# ๐งฌ typemapping
**Advanced Type Compatibility and Runtime Checking for Python 3.8+**
`typemapping` is a powerful and extensible package for deep type introspection and runtime type validation. It goes far beyond Python's built-in `isinstance` and `issubclass`, supporting generic types, `Annotated`, `Union`, specialized collections, and more โ with compatibility across Python 3.8+ including `typing_extensions` support.
---
## ๐ Features
* โ
Generic type compatibility (`List[int] ~ Sequence[int]`)
* ๐ง Concrete-to-abstract compatibility (`Counter`, `OrderedDict`, `ChainMap`)
* ๐ Full `Union` and `Optional` type support
* ๐ ๏ธ Python 3.8+ `Annotated` compatibility layer
* ๐งช Runtime type validation with container sampling
* ๐ Field and function argument mapping with `Annotated` metadata extraction
* ๐ฆ Framework-friendly: works with FastAPI, Pydantic, SQLAlchemy, etc.
---
## ๐ฆ Installation
```bash
pip install typemapping
```
> โ ๏ธ `typing_extensions` is required for full support on Python 3.8.
---
## ๐งโ๐ป Example
```python
from typing import List, Annotated
from typemapping.type_check import extended_isinstance
# Check generic type compatibility
print(extended_isinstance([1, 2, 3], List[int])) # True
print(extended_isinstance([1, 2, 3], List[str])) # False
```
---
## ๐งฉ Key APIs
### ๐ Type Checking & Compatibility
* `extended_isinstance(obj, type_hint)`
* `generic_issubclass(subtype, supertype)`
* `is_equal_type(t1, t2)`
* `defensive_issubclass(cls, classinfo)`
### ๐งฌ Annotated Type Handling
* `is_annotated_type(type)`
* `strip_annotated(type)`
* `get_annotated_metadata(type)`
### ๐ง Function and Class Introspection
* `get_func_args(func)`
* `map_model_fields(cls)`
* `map_dataclass_fields(cls)`
* `get_field_type(cls, fieldname)`
### ๐ Origin Compatibility
* `is_equivalent_origin(t1, t2)`
* `get_equivalent_origin(t)`
* `is_fully_compatible(t1, t2)`
* `get_compatibility_chain(t)`
---
## โ๏ธ Compatibility
* โ
Python 3.8 and above
* ๐ Backward-compatible via `typing_extensions`
---
## ๐งช Running Tests
```bash
pytest
```
---
## ๐ License
MIT License
---
## ๐ค Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
Raw data
{
"_id": null,
"home_page": null,
"name": "typemapping",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "typing, type-checking, generics, variance, annotations",
"author": null,
"author_email": "rodbell <bellirodrigo2@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c6/f3/7c55b19f06f7971adddc71270fda1f0df99343a2cee3cd21ad3dffb6a210/typemapping-0.1.6.tar.gz",
"platform": null,
"description": "# \ud83e\uddec typemapping\r\n\r\n**Advanced Type Compatibility and Runtime Checking for Python 3.8+**\r\n\r\n`typemapping` is a powerful and extensible package for deep type introspection and runtime type validation. It goes far beyond Python's built-in `isinstance` and `issubclass`, supporting generic types, `Annotated`, `Union`, specialized collections, and more \u2014 with compatibility across Python 3.8+ including `typing_extensions` support.\r\n\r\n---\r\n\r\n## \ud83d\ude80 Features\r\n\r\n* \u2705 Generic type compatibility (`List[int] ~ Sequence[int]`)\r\n* \ud83e\udde0 Concrete-to-abstract compatibility (`Counter`, `OrderedDict`, `ChainMap`)\r\n* \ud83d\udd01 Full `Union` and `Optional` type support\r\n* \ud83d\udee0\ufe0f Python 3.8+ `Annotated` compatibility layer\r\n* \ud83e\uddea Runtime type validation with container sampling\r\n* \ud83d\udd0d Field and function argument mapping with `Annotated` metadata extraction\r\n* \ud83d\udce6 Framework-friendly: works with FastAPI, Pydantic, SQLAlchemy, etc.\r\n\r\n---\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\npip install typemapping\r\n```\r\n\r\n> \u26a0\ufe0f `typing_extensions` is required for full support on Python 3.8.\r\n\r\n---\r\n\r\n## \ud83e\uddd1\u200d\ud83d\udcbb Example\r\n\r\n```python\r\nfrom typing import List, Annotated\r\nfrom typemapping.type_check import extended_isinstance\r\n\r\n# Check generic type compatibility\r\nprint(extended_isinstance([1, 2, 3], List[int])) # True\r\nprint(extended_isinstance([1, 2, 3], List[str])) # False\r\n```\r\n\r\n---\r\n\r\n## \ud83e\udde9 Key APIs\r\n\r\n### \ud83d\udd0e Type Checking & Compatibility\r\n\r\n* `extended_isinstance(obj, type_hint)`\r\n* `generic_issubclass(subtype, supertype)`\r\n* `is_equal_type(t1, t2)`\r\n* `defensive_issubclass(cls, classinfo)`\r\n\r\n### \ud83e\uddec Annotated Type Handling\r\n\r\n* `is_annotated_type(type)`\r\n* `strip_annotated(type)`\r\n* `get_annotated_metadata(type)`\r\n\r\n### \ud83e\udde0 Function and Class Introspection\r\n\r\n* `get_func_args(func)`\r\n* `map_model_fields(cls)`\r\n* `map_dataclass_fields(cls)`\r\n* `get_field_type(cls, fieldname)`\r\n\r\n### \ud83d\udd01 Origin Compatibility\r\n\r\n* `is_equivalent_origin(t1, t2)`\r\n* `get_equivalent_origin(t)`\r\n* `is_fully_compatible(t1, t2)`\r\n* `get_compatibility_chain(t)`\r\n\r\n---\r\n\r\n## \u2699\ufe0f Compatibility\r\n\r\n* \u2705 Python 3.8 and above\r\n* \ud83d\udd04 Backward-compatible via `typing_extensions`\r\n\r\n---\r\n\r\n## \ud83e\uddea Running Tests\r\n\r\n```bash\r\npytest\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcc4 License\r\n\r\nMIT License\r\n\r\n---\r\n\r\n## \ud83e\udd1d Contributing\r\n\r\nContributions are welcome! Feel free to open issues or submit pull requests.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Advanced type compatibility and checking system for Python",
"version": "0.1.6",
"project_urls": null,
"split_keywords": [
"typing",
" type-checking",
" generics",
" variance",
" annotations"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "3cb68429af8cba9d56bdf028bcc4f6bb31fb36e842a69e6ad937fb8460f1c980",
"md5": "7702e64172a2d9caf8e1462eda239efe",
"sha256": "e0294ff62682fc54f7a7fa356bc33dcb3a48454722b9458f59a44c9a33e2fab3"
},
"downloads": -1,
"filename": "typemapping-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7702e64172a2d9caf8e1462eda239efe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 22736,
"upload_time": "2025-08-05T12:17:49",
"upload_time_iso_8601": "2025-08-05T12:17:49.664348Z",
"url": "https://files.pythonhosted.org/packages/3c/b6/8429af8cba9d56bdf028bcc4f6bb31fb36e842a69e6ad937fb8460f1c980/typemapping-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c6f37c55b19f06f7971adddc71270fda1f0df99343a2cee3cd21ad3dffb6a210",
"md5": "4f38bbaf294981b65540a78225877c92",
"sha256": "4d3d51e511893334767b41af7ea8487df50a2e7967bb9537b2398a3976999187"
},
"downloads": -1,
"filename": "typemapping-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "4f38bbaf294981b65540a78225877c92",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 44012,
"upload_time": "2025-08-05T12:17:50",
"upload_time_iso_8601": "2025-08-05T12:17:50.747523Z",
"url": "https://files.pythonhosted.org/packages/c6/f3/7c55b19f06f7971adddc71270fda1f0df99343a2cee3cd21ad3dffb6a210/typemapping-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-05 12:17:50",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "typemapping"
}