Skip to main content

A tool to convert Python files to a JSON file.

Project description

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.

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

pycodes2json-1.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycodes2json-1.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file pycodes2json-1.1.0.tar.gz.

File metadata

  • Download URL: pycodes2json-1.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for pycodes2json-1.1.0.tar.gz
Algorithm Hash digest
SHA256 11270d55e625c8ce6ad68e16e7e6e3aeeeb0eaa286b63df3f76a36ba4358afba
MD5 116551c55ca067eea859433abb018b6e
BLAKE2b-256 14b6284509daf23ac8350e71eb28465db9cec426c8040ea78e50613ecf1e571e

See more details on using hashes here.

File details

Details for the file pycodes2json-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycodes2json-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for pycodes2json-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 563b86fa869570231314a629c8dda194ab1e1b9315165312d2a07e510ae55465
MD5 75f5d1836a9fed82fd4445bb6daf3b0d
BLAKE2b-256 462b539e745487fad15cf90c3b3978c41acd07538c9ddcdaded5bf26833275f6

See more details on using hashes here.

Supported by

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