Skip to main content

A flexible, high-performance utility for creating project snapshots and searching files with a rich terminal UI.

Project description

dirshot 📸

PyPI version License: MIT Python Version

A flexible, high-performance utility for creating project snapshots and searching files, complete with rich visual feedback in your terminal.

dirshot scans your project directories to either create a single, comprehensive text file "snapshot" of your codebase or to search for specific keywords within your files. It's perfect for feeding project context to Large Language Models (LLMs), archiving codebases, conducting security audits, or simply navigating complex projects.


✨ Key Features

  • Rich Terminal Visuals: Powered by rich, dirshot provides a beautiful and informative live view of its progress, including spinners, progress bars, summary tables, and thread activity. It falls back to a simple text-based progress indicator if rich is not installed.
  • Powerful Presets: Comes with an extensive list of LanguagePreset and IgnorePreset enums to instantly configure scans for dozens of languages, frameworks, and tools (Python, JavaScript, Go, Rust, Terraform, Docker, etc.).
  • Dual Modes:
    • Snapshot Mode: Collate all project files matching your criteria into a single, easy-to-share output file.
    • Search Mode: Hunt for specific keywords in filenames or, optionally, within file contents.
  • Highly Customizable: Fine-tune scans by combining presets with manual lists of file extensions, ignore paths, and specific file names to include or exclude.
  • Concurrent & Fast: Uses a ThreadPoolExecutor for high-performance file discovery and processing, making scans quick and efficient.
  • Detailed Output: Generates an optional file tree, shows detailed scan summaries, and can even approximate token/character counts, which is useful for LLM context limits.

📦 Installation

You can install dirshot directly from PyPI.

Basic Installation (no visual dependencies):

pip install dirshot

Installation with Enhanced Terminal Visuals:

To get the full rich terminal experience, install the rich extra, which adds support for rich.

pip install dirshot[rich]

🚀 How to Use

dirshot is used by importing the generate_snapshot function into a Python script.

Here is a basic example of creating a snapshot of a Python project:

# snapshot_script.py
from src.dirshot import generate_snapshot, LanguagePreset, IgnorePreset
# or 
# from src.dirshot import *

generate_snapshot(
    root_directory=".", # optional
    output_file_name="my_python_project.txt",
    language_presets=[LanguagePreset.PYTHON, LanguagePreset.MARKUP],
    ignore_presets=[
        IgnorePreset.VERSION_CONTROL, # Ignore .git
        IgnorePreset.PYTHON,          # Ignore __pycache__, venv, etc.
        IgnorePreset.IDE_METADATA     # Ignore .vscode, .idea
    ],
    generate_tree=True,
    show_token_count=True
)

To run this, save the code as a Python file (e.g., snapshot_script.py) and execute it from your terminal:

python snapshot_script.py

📋 Examples

The examples.py file in the repository contains many more use cases. Here are a few common ones:

1. Full-Stack Web App (React + Node.js)

This example combines multiple presets to capture a full-stack JavaScript project while ignoring common clutter like node_modules.

generate_snapshot(
    root_directory=".",
    output_file_name="fullstack_js_snapshot.txt",
    language_presets=[
        LanguagePreset.REACT,      # Handles all frontend JS/TS/JSX files
        LanguagePreset.WEB_FRONTEND  # Includes HTML and CSS files
    ],
    ignore_presets=[
        IgnorePreset.NODE_JS,      # Crucial for ignoring node_modules
        IgnorePreset.IDE_METADATA,
        IgnorePreset.BUILD_ARTIFACTS,
        IgnorePreset.VERSION_CONTROL
    ],
    generate_tree=True,
    show_tree_stats=True
)

2. Data Science Project (Python, Notebooks & SQL)

Collate all relevant files from a data analysis or machine learning project.

generate_snapshot(
    root_directory="./data_science_project",
    output_file_name="data_science_snapshot.txt",
    language_presets=[
        LanguagePreset.PYTHON,
        LanguagePreset.DATA_SCIENCE_NOTEBOOKS, # .ipynb
        LanguagePreset.SQL,
        LanguagePreset.MARKUP # Include READMEs
    ],
    ignore_presets=[
        IgnorePreset.PYTHON,             # Ignores venv, __pycache__, etc.
        IgnorePreset.JUPYTER_NOTEBOOKS,  # Ignores .ipynb_checkpoints
        IgnorePreset.IDE_METADATA,
        IgnorePreset.VERSION_CONTROL
    ]
)

3. Search for Secrets or API Keys

Use "Search Mode" to perform a security audit. This example intentionally omits the SECRET_FILES ignore preset to ensure .env files are searched.

generate_snapshot(
    root_directory=".",
    output_file_name="secrets_audit_results.txt",
    search_keywords=["password", "secret_key", "api_key", "token"],
    language_presets=[LanguagePreset.CONFIGURATION],
    search_file_contents=True,
    ignore_presets=[
        IgnorePreset.VERSION_CONTROL,
        IgnorePreset.NODE_JS,
        IgnorePreset.BUILD_ARTIFACTS
        # Deliberately not ignoring SECRET_FILES
    ]
)

⚙️ API Reference

The generate_snapshot() function accepts the following parameters:

Parameter Type Default Description
root_directory str "." The starting directory for the scan.
output_file_name str "project_snapshot.txt" The name of the file to save the results to.
search_keywords Optional[List[str]] None If provided, switches to Search Mode. Otherwise, runs in Snapshot Mode.
files Optional[List[str]] None A list of specific filenames to include. If provided, checks this list first before extensions.
language_presets Optional[List[LanguagePreset]] None A list of LanguagePreset enums for common file types (e.g., LanguagePreset.PYTHON).
ignore_presets Optional[List[IgnorePreset]] None A list of IgnorePreset enums for common ignore patterns (e.g., IgnorePreset.NODE_JS).
file_extensions Optional[List[str]] None A manual list of file extensions to include (e.g., [".py", ".md"]).
ignore_if_in_path Optional[List[str]] None A list of directory or file substring names to exclude (e.g., ["temp"] excludes src/temp/file.py).
ignore_extensions Optional[List[str]] None A manual list of file extensions to explicitly ignore (e.g., [".log", ".tmp"]).
search_file_contents bool True In Search Mode, search for keywords within file contents.
generate_tree bool True Include a file tree of the matched files at the top of the output.
show_tree_stats bool False Display file and directory counts in the generated tree.
show_token_count bool False Display an approximated token/character count in the summary and output file.
exclude_whitespace_in_token_count bool False If True, removes whitespace before counting tokens for a more compact count.
max_workers Optional[int] CPU count + 4 The maximum number of worker threads for concurrent processing.
read_binary_files bool False If True, the content search will attempt to read and search through binary files.
only_show_tree bool False If True, the output file will contain only the file tree (and stats), omitting file content.
case_sensitive_filter bool False If True, file filtering (extensions, ignore paths) is case-sensitive.
case_sensitive_search bool False If True, keyword searching is case-sensitive.

🤝 Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some feature').
  5. Push to the branch (git push origin feature/your-feature-name).
  6. Open a pull request.

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

dirshot-0.3.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dirshot-0.3.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file dirshot-0.3.0.tar.gz.

File metadata

  • Download URL: dirshot-0.3.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for dirshot-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e1661814369e501758baca7eefdcb64f78a30fccfebe96f3dc2eb790578efcfb
MD5 c1660d671b7e88923025b362e2a86d36
BLAKE2b-256 1bf52aad653bc8602fea56bbcd764c3a2ad9606f2247f689b6d44f0b1bc4f7f3

See more details on using hashes here.

File details

Details for the file dirshot-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dirshot-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for dirshot-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6992a7e13ac18ed8feca4444771e5e577de3d1bc9f468cc55cf492ca40f6ddad
MD5 6c663d84543c6fa9eb23f86bbf38af9d
BLAKE2b-256 9df7875ef81267728bdbce36887b037bb4a5a63f68d6f8f367ac0f04227f6920

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