Skip to main content

Edit Python code with ease.

Project description

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, and find_set.
  • In-Place Modification: Directly modify lists, dictionaries, and sets within your source code through simple method calls.
  • Automatic File Handling: Use the File context 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code-crafter-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

code_crafter-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file code-crafter-0.1.0.tar.gz.

File metadata

  • Download URL: code-crafter-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for code-crafter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07c89fd51dd2291db482a1d3d59bff7163e6086ed61cb703b8d65a5ddb9c797f
MD5 4bf8432ab6598fa30905a057658a13ed
BLAKE2b-256 595781730c040173b57132852ea7990048b0675fc2211fede22fecb36103aa40

See more details on using hashes here.

File details

Details for the file code_crafter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: code_crafter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for code_crafter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c59dbc461941023b541aa02d4dc52f41dfb1865475af1e7bf64ee6dee4556b8
MD5 c85cba63ada2fecb02a949b88d0195d3
BLAKE2b-256 b08ee24261c7ca3bee88383173e6b035db0543f3bc49e9775eb6d1b461b093e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page