Skip to main content

py2json

py2json is a Python package that scans a directory and its subdirectories for .py files, excluding hidden directories (those starting with a .), and merges their contents into a single JSON file. It simplifies the process of aggregating Python code into a structured JSON format for further analysis or processing.

Features

  • Automatically scans a specified directory and its subdirectories for .py files, skipping hidden directories.
  • Outputs the merged contents into a well-formatted JSON file.
  • Handles exceptions for missing directories, permissions, and unexpected errors.

Installation

Install the package using pip:

pip install py2json

Usage

After installation, use the command-line interface (CLI) tool:

py2json <directory_path> <output_json_path>

Parameters

  • <directory_path>: Path to the directory containing .py files.
  • <output_json_path>: Path to save the resulting JSON file.

Example

Suppose you have a directory named scripts containing .py files and subdirectories. To merge them into a JSON file named output.json, run:

py2json scripts output.json

This will create a JSON file output.json with the contents of all .py files in the scripts directory and its subdirectories, excluding hidden directories.

Exception Handling

The package gracefully handles the following errors:

  • FileNotFoundError: If the specified directory does not exist.
  • PermissionError: If the script lacks permissions to read files or write the output file.
  • Other Errors: Any unexpected errors are logged for debugging.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for pycodes2json 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycodes2json 1.1.0
File Size Uploaded
pycodes2json-1.1.0.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycodes2json 1.1.0
File Interpreter ABI Platform
pycodes2json-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / pycodes2json-1.1.0.tar.gz

Download URL pycodes2json-1.1.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
11270d55e625c8ce6ad68e16e7e6e3aeeeb0eaa286b63df3f76a36ba4358afba
BLAKE2b-256 checksum
How to use checksums
14b6284509daf23ac8350e71eb28465db9cec426c8040ea78e50613ecf1e571e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.6

Release files / pycodes2json-1.1.0-py3-none-any.whl

Download URL pycodes2json-1.1.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
563b86fa869570231314a629c8dda194ab1e1b9315165312d2a07e510ae55465
BLAKE2b-256 checksum
How to use checksums
462b539e745487fad15cf90c3b3978c41acd07538c9ddcdaded5bf26833275f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page