DTJ (Directory-to-JSON)
Overview
DTJ (Directory-to-JSON) is a Python command-line tool, particularly useful for quickly generating and sharing representations of directory structures and their contents in a structured and token-efficient manner, making it ideal for interactions with language models like ChatGPT.
Example output
dtj
{
"my_project": {
"__init__.py": "",
"main.py": "# Main application file\nimport app\n\napp.run()",
"app.py": "# App module\n\ndef run():\n print('Running the app')",
"utils": {
"helper.py": "# Utility functions\n\ndef helper():\n return 'Helper function'"
}
}
}
Features
- Convert directory contents to JSON format.
- Include or exclude files using patterns (supports fnmatch style, e.g.,
*.py,data*). - Recursive directory parsing.
- Options for output: printing to console, saving to a file, or copying to the clipboard.
Updates
- new JSON format reduces token usage ~30%
Installation
pip install dtj
Usage
Run DTJ from the command line with the following options:
dtj <target-directory> [options]
If no target directory is specified, DTJ will default to the current working directory.
Options:
-tor--target-file: Target a single file. This option is mutually exclusive with-i,-e, and-r.-ior--include: Patterns to include files. Enclose patterns in quotes to avoid shell expansion (e.g.,'*.py','data*').-eor--exclude: Patterns to exclude files. Enclose patterns in quotes to avoid shell expansion (e.g.,'*.xml','temp*').-oor--output-file: Set the output JSON file name.-ror--recursive: Enable recursive search in directories. Not valid when targeting a single file.-por--print: Print the output using rich formatting.-cor--clipboard: Copy the output to the clipboard.
Example
simple
dtj
Generates an output.json with the content
advanced
dtj myfolder -i '*.py' '*.html' -o output.json -r
This command will parse all .py and .html files in myfolder recursively and save the JSON output to output.json.
Using it alongside gptwc
dtj | gptwc
outputs the token count
1337
Authors
- Adrian Galilea - Initial work
Acknowledgments
- Hat tip to ChatGPT for assistance with project setup and documentation.
Metadata
Release files for dtj 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dtj-0.1.8.tar.gz | 6.0 kB | Without provenance | Details for dtj-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dtj-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for dtj-0.1.8-py3-none-any.whl |
Total release size: 14.2 kB
Release files / dtj-0.1.8.tar.gz
| Download URL | dtj-0.1.8.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de05b2884c686fc82e3da1e6e43269df285531cd526a23525d481ee63e42a16d
|
|
BLAKE2b-256 checksum How to use checksums |
9f0dc81197d3fb7cb2c7227e4225d1461c5f085ca14968b77d35ec5ffb5e02ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Release files / dtj-0.1.8-py3-none-any.whl
| Download URL | dtj-0.1.8-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a40bdc27bd7013bdc092ddc08f7ea537999e8467c3e5c20461d92842b11de00
|
|
BLAKE2b-256 checksum How to use checksums |
2a9de8567a8a2559764843e547b4e2bcbcda356101b5dd05e8aca54583c3a3ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Security for dtj 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.