Treat a directory like a dataclass for recursive file listing and reading.
Project description
dirclass
Treat a directory like a dataclass for ease, recursively.
Main features
- Simple factory:
dirclass(path, recursive=True, file_types="*") -> dataclass - List files:
d.all()returns a flattened list of file paths - Read files:
d.read_all()returns a flattened list of file contents - Filtering: Accept glob patterns like
"*.py"or["*.py", "*.md"]in constructor or per-call - Subfolder properties: Immediate subfolders become attributes (e.g.,
.src,.data)- Aliases: full sanitized name, tail after last dot (e.g.,
path.src→.path_srcand.src), and case-insensitive access (e.g.,.Galleryand.gallery)
- Aliases: full sanitized name, tail after last dot (e.g.,
- Robust reading: Read errors are logged and skipped (continues processing)
Install (PyPI)
pip install dirclass
Alternatively,
pip install -e .
Usage
from dirclass import dirclass
# Create a directory wrapper
d = dirclass("/path/to/folder", recursive=True, file_types=["*.py", "*.md"])
# List all matching files
paths = d.all() # list[str]
# Read contents of all matching files
contents = d.read_all() # list[str]
# Override filters per call
py_only = d.all("*.py")
md_and_txt_contents = d.read_all(["*.md", "*.txt"])
# Subfolder properties (immediate children of the root)
# If your root has folders: src, data, and Gallery
src_files = d.src # files under /path/to/folder/src
data_files = d.data # files under /path/to/folder/data
gallery_files = d.Gallery # case-insensitive access also works: d.gallery
# Dotted folder names (e.g., `path.src`) expose multiple aliases
# - full sanitized name: d.path_src
# - tail alias: d.src
Example
from dirclass import dirclass
d = dirclass("./project", recursive=True, file_types=["*.py", "*.md"])
print("All files:")
for p in d.all():
print(p)
print("\nPython files only:")
for p in d.all("*.py"):
print(p)
print("\nSubfolder: src")
for p in d.src: # requires a ./project/src subfolder
print(p)
print("\nReading markdown contents:")
for content in d.read_all("*.md"):
print(content[:80], "...")
Codes are generated by GPT5, thus may not be reliable in the current version for test.
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 dirclass-0.1.0.tar.gz.
File metadata
- Download URL: dirclass-0.1.0.tar.gz
- Upload date:
- Size: 5.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 |
ae6e156dddb38d268cd7808378009513b0a6848594df63990022cd4ed8abcb0e
|
|
| MD5 |
0606735c7b76a33a7e1102b9415918e1
|
|
| BLAKE2b-256 |
e4f1ad00679b03f4e227a23e74e04dbb078e327c804bd68659081e35fa6dc137
|
Provenance
The following attestation bundles were made for dirclass-0.1.0.tar.gz:
Publisher:
python-publish.yml on reycn/dirclass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dirclass-0.1.0.tar.gz -
Subject digest:
ae6e156dddb38d268cd7808378009513b0a6848594df63990022cd4ed8abcb0e - Sigstore transparency entry: 393529937
- Sigstore integration time:
-
Permalink:
reycn/dirclass@fc53a1805dfa710a192072a275d576edd2f788db -
Branch / Tag:
refs/tags/stable - Owner: https://github.com/reycn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fc53a1805dfa710a192072a275d576edd2f788db -
Trigger Event:
release
-
Statement type:
File details
Details for the file dirclass-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dirclass-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 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 |
20c4862d1e0e7a7e987f1b4646b11b250222265219cefed03151c67c423d6da8
|
|
| MD5 |
2405aceeb8b738c5f2afeb17b71c9421
|
|
| BLAKE2b-256 |
2d4f30a411fc46cf6a333953e0700170177890cd5a80f87783e488f64991a00e
|
Provenance
The following attestation bundles were made for dirclass-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on reycn/dirclass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dirclass-0.1.0-py3-none-any.whl -
Subject digest:
20c4862d1e0e7a7e987f1b4646b11b250222265219cefed03151c67c423d6da8 - Sigstore transparency entry: 393529939
- Sigstore integration time:
-
Permalink:
reycn/dirclass@fc53a1805dfa710a192072a275d576edd2f788db -
Branch / Tag:
refs/tags/stable - Owner: https://github.com/reycn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fc53a1805dfa710a192072a275d576edd2f788db -
Trigger Event:
release
-
Statement type: