Code Crafter
Code Crafter is a Python library designed for manipulating Python source code through Abstract Syntax Tree (AST) transformations. This tool simplifies the process of programmatically editing Python code, allowing developers to find and modify specific data structures such as lists, dictionaries, and sets within their code. Whether you're building code generation tools, refactoring code, or creating dynamic Python scripts, Code Crafter offers a clean and intuitive API to achieve your goals.
Features
- Easy Navigation: Navigate through your Python code's AST with ease, thanks to intuitive methods like
find_list,find_dict, andfind_set. - In-Place Modification: Directly modify lists, dictionaries, and sets within your source code through simple method calls.
- Automatic File Handling: Use the
Filecontext manager to automatically read, modify, and write back changes to your Python files. - Support for Common Data Structures: First-class support for manipulating lists, dictionaries, and sets, with potential for future expansion.
Installation
Install Code Crafter using pip:
pip install code-crafter
Quick Start
Here's a quick example to get you started with Code Crafter:
import code_crafter as cc
# Automatically apply changes to 'my_file.py'
with cc.File("my_file.py") as file:
# Append an element to a list named 'my_list'
file.find_list("my_list").append(4)
# Add a new key-value pair to a dictionary named 'my_dict'
file.find_dict("my_dict").update(my_new_key="my_new_value")
# Add a new element to a set named 'my_set'
file.find_set("my_set").add(42)
cc.List supports the following methods:
- append
- extend
- insert
- remove
- pop
- clear
- reverse
cc.Dict supports the following methods:
- update
- clear
- pop
- get
cc.Set supports the following methods:
- add
- remove
- update
- discard
Contributing
Contributions to Code Crafter are welcome! Whether it's bug reports, feature requests, or code contributions, please feel free to open an issue or a pull request on our GitHub repository.
License
Code Crafter is released under the MIT License. See the LICENSE file for more details.
Release files for code-crafter 0.1.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 | |
|---|---|---|---|
| code-crafter-0.1.0.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| code_crafter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.9 kB
Release files / code-crafter-0.1.0.tar.gz
| Download URL | code-crafter-0.1.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07c89fd51dd2291db482a1d3d59bff7163e6086ed61cb703b8d65a5ddb9c797f
|
|
BLAKE2b-256 checksum How to use checksums |
595781730c040173b57132852ea7990048b0675fc2211fede22fecb36103aa40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / code_crafter-0.1.0-py3-none-any.whl
| Download URL | code_crafter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c59dbc461941023b541aa02d4dc52f41dfb1865475af1e7bf64ee6dee4556b8
|
|
BLAKE2b-256 checksum How to use checksums |
b08ee24261c7ca3bee88383173e6b035db0543f3bc49e9775eb6d1b461b093e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|