String ASCII tree from list or directory of filepaths
Project description
ASCII Tree from Paths
Create ASCII tree strings from list or directories of filepaths. Useful for formatting directory information into LLM context window.
Example usage
Basic Usage with Strings
example_paths = [
"src/main.py",
"src/utils/helpers.py",
"src/utils/config.py",
"src/utils/database.py",
"src/utils/auth.py",
"src/models/user.py",
"src/models/database.py",
"tests/test_main.py",
"tests/test_utils.py",
"tests/integration/test_api.py",
"tests/integration/test_db.py",
"docs/README.md",
"docs/api/endpoints.md",
"docs/api/authentication.md",
"requirements.txt",
".gitignore",
]
print("1. Basic tree (no limits):")
print(paths_to_tree(example_paths))
print("\n" + "=" * 60 + "\n")
print("2. With depth limit (max_depth=2):")
print(paths_to_tree(example_paths, max_depth=2))
print("\n" + "=" * 60 + "\n")
print("3. With separate file and directory limits (max_files_per_dir=2, max_dirs_per_dir=1):")
print(paths_to_tree(example_paths, max_files_per_dir=2, max_dirs_per_dir=1))
print("\n" + "=" * 60 + "\n")
print("4. With file limit only (max_files_per_dir=3):")
print(paths_to_tree(example_paths, max_files_per_dir=3))
print("\n" + "=" * 60 + "\n")
Output:
1. Basic tree (no limits):
├── src
│ ├── utils
│ │ ├── helpers.py
│ │ ├── config.py
│ │ ├── database.py
│ │ └── auth.py
│ ├── models
│ │ ├── user.py
│ │ └── database.py
│ └── main.py
├── tests
│ ├── integration
│ │ ├── test_api.py
│ │ └── test_db.py
│ ├── test_main.py
│ └── test_utils.py
├── docs
│ ├── api
│ │ ├── endpoints.md
│ │ └── authentication.md
│ └── README.md
├── requirements.txt
└── .gitignore
============================================================
2. With depth limit (max_depth=2):
├── src
│ ├── utils
│ │ ├── ... (depth limit reached)
│ ├── models
│ │ ├── ... (depth limit reached)
│ └── main.py
├── tests
│ ├── integration
│ │ ├── ... (depth limit reached)
│ ├── test_main.py
│ └── test_utils.py
├── docs
│ ├── api
│ │ ├── ... (depth limit reached)
│ └── README.md
├── requirements.txt
└── .gitignore
============================================================
3. With separate file and directory limits (max_files_per_dir=2, max_dirs_per_dir=1):
├── src
│ ├── utils
│ │ ├── helpers.py
│ │ ├── config.py
│ │ └── ... (2 more files)
│ ├── main.py
│ └── ... (1 more directories)
├── requirements.txt
├── .gitignore
└── ... (2 more directories)
============================================================
4. With file limit only (max_files_per_dir=3):
├── src
│ ├── utils
│ │ ├── helpers.py
│ │ ├── config.py
│ │ ├── database.py
│ │ └── ... (1 more files)
│ ├── models
│ │ ├── user.py
│ │ └── database.py
│ └── main.py
├── tests
│ ├── integration
│ │ ├── test_api.py
│ │ └── test_db.py
│ ├── test_main.py
│ └── test_utils.py
├── docs
│ ├── api
│ │ ├── endpoints.md
│ │ └── authentication.md
│ └── README.md
├── requirements.txt
└── .gitignore
Usage with Dictionary for Path and File Size
path_sizes = {
"src/main.py": 2048,
"src/utils/helpers.py": 1024,
"src/utils/config.py": 512,
"src/utils/database.py": 4096,
"src/utils/auth.py": 3072,
"src/models/user.py": 1536,
"tests/test_main.py": 2560,
"README.md": 1024,
"requirements.txt": 256,
}
print("5. With file sizes displayed:")
print(paths_to_tree(path_sizes, show_sizes=True))
print("\n" + "=" * 60 + "\n")
print("6. Sorted by size, 2 files per directory, 1 subdir per directory, sizes shown:")
print(
paths_to_tree(
path_sizes,
max_files_per_dir=2,
max_dirs_per_dir=1,
sort_by_size=True,
show_sizes=True,
)
)
print("\n" + "=" * 60 + "\n")
print("7. All limits combined:")
print(
paths_to_tree(
path_sizes,
max_depth=4,
max_files_per_dir=3,
max_dirs_per_dir=1,
sort_by_size=True,
show_sizes=True,
)
)
Output:
============================================================
5. With file sizes displayed:
├── src
│ ├── utils
│ │ ├── helpers.py (1.0KB)
│ │ ├── config.py (512B)
│ │ ├── database.py (4.0KB)
│ │ └── auth.py (3.0KB)
│ ├── models
│ │ └── user.py (1.5KB)
│ └── main.py (2.0KB)
├── tests
│ └── test_main.py (2.5KB)
├── README.md (1.0KB)
└── requirements.txt (256B)
============================================================
6. Sorted by size, 2 files per directory, 1 subdir per directory, sizes shown:
├── src
│ ├── utils
│ │ ├── database.py (4.0KB)
│ │ ├── auth.py (3.0KB)
│ │ └── ... (2 more files)
│ ├── main.py (2.0KB)
│ └── ... (1 more directories)
├── README.md (1.0KB)
├── requirements.txt (256B)
└── ... (1 more directories)
============================================================
7. All limits combined:
├── src
│ ├── utils
│ │ ├── database.py (4.0KB)
│ │ ├── auth.py (3.0KB)
│ │ ├── helpers.py (1.0KB)
│ │ └── ... (1 more files)
│ ├── main.py (2.0KB)
│ └── ... (1 more directories)
├── README.md (1.0KB)
├── requirements.txt (256B)
└── ... (1 more directories)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_ascii_tree-0.1.1.tar.gz.
File metadata
- Download URL: py_ascii_tree-0.1.1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4049b76eb1758a2a1de0979d85af440b4796366cd1264dfe1bba03695f31163
|
|
| MD5 |
ef27a425dfc4886fe7a43f325d7f62a9
|
|
| BLAKE2b-256 |
177e5fd5df68a9b0766773864b13528d1c1f6ee60a0584daa6683d33e115e00b
|
Provenance
The following attestation bundles were made for py_ascii_tree-0.1.1.tar.gz:
Publisher:
ci.yml on evamaxfield/py-ascii-tree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ascii_tree-0.1.1.tar.gz -
Subject digest:
c4049b76eb1758a2a1de0979d85af440b4796366cd1264dfe1bba03695f31163 - Sigstore transparency entry: 278158547
- Sigstore integration time:
-
Permalink:
evamaxfield/py-ascii-tree@6e3e7a8d225b7d4135618afe8cabd3a95fdc0c71 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/evamaxfield
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6e3e7a8d225b7d4135618afe8cabd3a95fdc0c71 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_ascii_tree-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_ascii_tree-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b6f4b2ecf9f6f71fe364281b988deb919d2f00a189479e01f76bfc2c6d9dfb2
|
|
| MD5 |
5224d973ebdbc30ce54fbd55ff8f98a5
|
|
| BLAKE2b-256 |
02a3c07e9ea23f58a673440e2b7637ecfdafd44290e391943da2ddf64fa62452
|
Provenance
The following attestation bundles were made for py_ascii_tree-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on evamaxfield/py-ascii-tree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ascii_tree-0.1.1-py3-none-any.whl -
Subject digest:
4b6f4b2ecf9f6f71fe364281b988deb919d2f00a189479e01f76bfc2c6d9dfb2 - Sigstore transparency entry: 278158556
- Sigstore integration time:
-
Permalink:
evamaxfield/py-ascii-tree@6e3e7a8d225b7d4135618afe8cabd3a95fdc0c71 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/evamaxfield
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6e3e7a8d225b7d4135618afe8cabd3a95fdc0c71 -
Trigger Event:
push
-
Statement type: