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.0.0.tar.gz (2.9 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.0.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pycodes2json-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c7e004f4c01623feeb07cba39e0bcb1512a5ee448441e9b0960b14542d338ed
MD5 3d7d4ae15e53dee478fefe8710309ce2
BLAKE2b-256 9db87c5644033923302c8b70beff33a9a4aec153511532f4d088c93fc7acb82f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycodes2json-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13863b95eb4c8548948a4fb00260f9dff2dc729586cad750c5d7709e73939dff
MD5 1d0825ec518bc3a07ec8e9baba43751d
BLAKE2b-256 008a1fdb69505dd3b255528e97e34d122bd0bbd212b14b0f03c42d933555c651

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