Name | dirclass JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | Treat a directory like a dataclass for recursive file listing and reading. |
upload_time | 2025-08-14 08:17:04 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
files
directories
dataclass
recursion
utilities
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<!--
* @Date: 2025-08-14 15:41:37
* @LastEditors: Rongxin rongxin@u.nus.edu
* @LastEditTime: 2025-08-14 15:43:53
* @FilePath: /dirclass/README.md
-->
## 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_src` and `.src`), and case-insensitive access (e.g., `.Gallery` and `.gallery`)
- **Robust reading**: Read errors are logged and skipped (continues processing)
### Install (PyPI)
```bash
pip install dirclass
```
Alternatively,
```bash
pip install -e .
```
### Usage
```python
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
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "dirclass",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "files, directories, dataclass, recursion, utilities",
"author": null,
"author_email": "Rongxin Ouyang <rongxin@u.nus.edu>",
"download_url": "https://files.pythonhosted.org/packages/e4/f1/ad00679b03f4e227a23e74e04dbb078e327c804bd68659081e35fa6dc137/dirclass-0.1.0.tar.gz",
"platform": null,
"description": "<!--\n * @Date: 2025-08-14 15:41:37\n * @LastEditors: Rongxin rongxin@u.nus.edu\n * @LastEditTime: 2025-08-14 15:43:53\n * @FilePath: /dirclass/README.md\n-->\n## dirclass\n\nTreat a directory like a dataclass for ease, recursively.\n\n### Main features\n- **Simple factory**: `dirclass(path, recursive=True, file_types=\"*\") -> dataclass`\n- **List files**: `d.all()` returns a flattened list of file paths\n- **Read files**: `d.read_all()` returns a flattened list of file contents\n- **Filtering**: Accept glob patterns like `\"*.py\"` or `[\"*.py\", \"*.md\"]` in constructor or per-call\n- **Subfolder properties**: Immediate subfolders become attributes (e.g., `.src`, `.data`)\n - Aliases: full sanitized name, tail after last dot (e.g., `path.src` \u2192 `.path_src` and `.src`), and case-insensitive access (e.g., `.Gallery` and `.gallery`)\n- **Robust reading**: Read errors are logged and skipped (continues processing)\n\n### Install (PyPI)\n```bash\npip install dirclass\n```\nAlternatively, \n\n```bash\npip install -e .\n```\n\n### Usage\n```python\nfrom dirclass import dirclass\n\n# Create a directory wrapper\nd = dirclass(\"/path/to/folder\", recursive=True, file_types=[\"*.py\", \"*.md\"])\n\n# List all matching files\npaths = d.all() # list[str]\n\n# Read contents of all matching files\ncontents = d.read_all() # list[str]\n\n# Override filters per call\npy_only = d.all(\"*.py\")\nmd_and_txt_contents = d.read_all([\"*.md\", \"*.txt\"])\n\n# Subfolder properties (immediate children of the root)\n# If your root has folders: src, data, and Gallery\nsrc_files = d.src # files under /path/to/folder/src\ndata_files = d.data # files under /path/to/folder/data\ngallery_files = d.Gallery # case-insensitive access also works: d.gallery\n\n# Dotted folder names (e.g., `path.src`) expose multiple aliases\n# - full sanitized name: d.path_src\n# - tail alias: d.src\n```\n\n### Example\n```python\nfrom dirclass import dirclass\n\nd = dirclass(\"./project\", recursive=True, file_types=[\"*.py\", \"*.md\"]) \n\nprint(\"All files:\")\nfor p in d.all():\n print(p)\n\nprint(\"\\nPython files only:\")\nfor p in d.all(\"*.py\"):\n print(p)\n\nprint(\"\\nSubfolder: src\")\nfor p in d.src: # requires a ./project/src subfolder\n print(p)\n\nprint(\"\\nReading markdown contents:\")\nfor content in d.read_all(\"*.md\"):\n print(content[:80], \"...\")\n```\n\nCodes are generated by GPT5, thus may not be reliable in the current version for test.\n",
"bugtrack_url": null,
"license": null,
"summary": "Treat a directory like a dataclass for recursive file listing and reading.",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [
"files",
" directories",
" dataclass",
" recursion",
" utilities"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2d4f30a411fc46cf6a333953e0700170177890cd5a80f87783e488f64991a00e",
"md5": "2405aceeb8b738c5f2afeb17b71c9421",
"sha256": "20c4862d1e0e7a7e987f1b4646b11b250222265219cefed03151c67c423d6da8"
},
"downloads": -1,
"filename": "dirclass-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2405aceeb8b738c5f2afeb17b71c9421",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 6245,
"upload_time": "2025-08-14T08:17:02",
"upload_time_iso_8601": "2025-08-14T08:17:02.707668Z",
"url": "https://files.pythonhosted.org/packages/2d/4f/30a411fc46cf6a333953e0700170177890cd5a80f87783e488f64991a00e/dirclass-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e4f1ad00679b03f4e227a23e74e04dbb078e327c804bd68659081e35fa6dc137",
"md5": "0606735c7b76a33a7e1102b9415918e1",
"sha256": "ae6e156dddb38d268cd7808378009513b0a6848594df63990022cd4ed8abcb0e"
},
"downloads": -1,
"filename": "dirclass-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0606735c7b76a33a7e1102b9415918e1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 5628,
"upload_time": "2025-08-14T08:17:04",
"upload_time_iso_8601": "2025-08-14T08:17:04.134342Z",
"url": "https://files.pythonhosted.org/packages/e4/f1/ad00679b03f4e227a23e74e04dbb078e327c804bd68659081e35fa6dc137/dirclass-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-14 08:17:04",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dirclass"
}