# PyClassParser
`PyClassParser` is a Python library designed to parse Python class definitions and extract class attributes. It uses the `attrs` library for defining class attributes and ensures type safety with `attrs-strict`.
Currently it only supports Pydantic class format.
## Features
- Parses Python class definitions to extract class names and their attributes.
- Uses `attrs` for attribute definition and `attrs-strict` for type validation.
- Handles optional attributes and attributes with default values.
## Installation
To install `PyClassParser`, you need to have Python 3.x installed. You can install the required dependencies using `pip`:
```bash
pip install attrs attrs-strict
```
## Usage
Here's how you can use `PyClassParser` to parse Python class definitions:
### Example Code
Create a Python script, for example `example.py`:
```python
from pyclassparser import ClassParser
code = """
class MyClass:
attr1: int
attr2: str = "default"
class AnotherClass:
attr3: float
"""
parser = ClassParser(code=code)
print(parser.output)
print(parser.class_data_dict)
```
### Example Output
Running the above script should give you the parsed output of class definitions:
```
class MyClass:
attr1: int
attr2: str = "default"
class AnotherClass:
attr3: float
{'MyClass': [ClassATTR(attr_value='attr1', attr_type='int'), ClassATTR(attr_value='attr2', attr_type='str')],
'AnotherClass': [ClassATTR(attr_value='attr3', attr_type='float')]}
```
## Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
## License
This project is licensed under the MIT License.
## Acknowledgements
This library utilizes `attrs` and `attrs-strict` for attribute definition and type validation. Special thanks to the authors and contributors of these libraries.
Raw data
{
"_id": null,
"home_page": null,
"name": "pyclassparser",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "pydantic, parser, tool, schemas",
"author": null,
"author_email": "\"Carlos A. Planch\u00f3n\" <carlosandresplanchonprestes@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/14/cb/66e5ba4f9d4189b28e3ad119a642da70724560928a681ef9271e97b9af49/pyclassparser-0.6.tar.gz",
"platform": null,
"description": "# PyClassParser\n\n`PyClassParser` is a Python library designed to parse Python class definitions and extract class attributes. It uses the `attrs` library for defining class attributes and ensures type safety with `attrs-strict`.\n\nCurrently it only supports Pydantic class format.\n\n## Features\n\n- Parses Python class definitions to extract class names and their attributes.\n- Uses `attrs` for attribute definition and `attrs-strict` for type validation.\n- Handles optional attributes and attributes with default values.\n\n## Installation\n\nTo install `PyClassParser`, you need to have Python 3.x installed. You can install the required dependencies using `pip`:\n\n```bash\npip install attrs attrs-strict\n```\n\n## Usage\n\nHere's how you can use `PyClassParser` to parse Python class definitions:\n\n### Example Code\n\nCreate a Python script, for example `example.py`:\n\n```python\nfrom pyclassparser import ClassParser\n\ncode = \"\"\"\nclass MyClass:\n attr1: int\n attr2: str = \"default\"\n\nclass AnotherClass:\n attr3: float\n\"\"\"\nparser = ClassParser(code=code)\nprint(parser.output)\nprint(parser.class_data_dict)\n```\n\n### Example Output\n\nRunning the above script should give you the parsed output of class definitions:\n\n```\nclass MyClass:\n attr1: int\n attr2: str = \"default\"\n\nclass AnotherClass:\n attr3: float\n\n{'MyClass': [ClassATTR(attr_value='attr1', attr_type='int'), ClassATTR(attr_value='attr2', attr_type='str')], \n 'AnotherClass': [ClassATTR(attr_value='attr3', attr_type='float')]}\n```\n\n## Contributing\n\nContributions are welcome! Please submit a pull request or open an issue to discuss your ideas.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Acknowledgements\n\nThis library utilizes `attrs` and `attrs-strict` for attribute definition and type validation. Special thanks to the authors and contributors of these libraries.\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Parse Python classes and attributes from a string of Python code.",
"version": "0.6",
"project_urls": {
"repository": "https://github.com/carlosplanchon/pyclassparser.git"
},
"split_keywords": [
"pydantic",
" parser",
" tool",
" schemas"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7baf604ba36c4795b625ff471367830039ae019b991e2e19e651fe2259a94326",
"md5": "536e495baf1a59497381c1dcf74daefd",
"sha256": "6553e3cec1895f075a60d7aae9318f18c4ba38f22619d779396a18c0db513191"
},
"downloads": -1,
"filename": "pyclassparser-0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "536e495baf1a59497381c1dcf74daefd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4241,
"upload_time": "2024-05-18T18:26:13",
"upload_time_iso_8601": "2024-05-18T18:26:13.027525Z",
"url": "https://files.pythonhosted.org/packages/7b/af/604ba36c4795b625ff471367830039ae019b991e2e19e651fe2259a94326/pyclassparser-0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "14cb66e5ba4f9d4189b28e3ad119a642da70724560928a681ef9271e97b9af49",
"md5": "22bb7da92179702d6695c158566b592b",
"sha256": "d1be7392cb02269f996d1eed3be018e9a073747f62b87acbeda628367ba4564c"
},
"downloads": -1,
"filename": "pyclassparser-0.6.tar.gz",
"has_sig": false,
"md5_digest": "22bb7da92179702d6695c158566b592b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4024,
"upload_time": "2024-05-18T18:26:14",
"upload_time_iso_8601": "2024-05-18T18:26:14.710035Z",
"url": "https://files.pythonhosted.org/packages/14/cb/66e5ba4f9d4189b28e3ad119a642da70724560928a681ef9271e97b9af49/pyclassparser-0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-18 18:26:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "carlosplanchon",
"github_project": "pyclassparser",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "attrs",
"specs": [
[
">=",
"23.2.0"
]
]
},
{
"name": "attrs_strict",
"specs": [
[
">=",
"1.0.1"
]
]
}
],
"lcname": "pyclassparser"
}