Skip to main content

A flexible utility for creating project snapshots and searching for files.

Reason this release was yanked:

Need to fix links to repo

Project description

Dirshot: A Flexible Project Snapshot and Search Tool

Dirshot is a Python utility that creates snapshots of a project's directory structure and file contents. It can operate in two modes: filtering files based on their type and path, or searching for files based on keywords in their name or content.

The script generates a single output file containing a directory tree and the concatenated text of the selected files. This is useful for quickly gathering project context for code analysis, sharing with collaborators, or providing to a Large Language Model (LLM).

Key Features

  • Two Operating Modes:
    • Filter Mode: Create a snapshot of your project by filtering files based on extensions, filenames, and directory paths.
    • Search Mode: Search for files containing specific keywords in their name, path, or content.
  • Customizable Filtering:
    • Use language presets for popular languages (Python, JavaScript, Java, etc.).
    • Use ignore presets to exclude common files and directories (e.g., .git, node_modules, __pycache__).
    • Define custom file types, and whitelist/blacklist substrings in filenames and paths.
  • Flexible Tree Generation:
    • Display a directory tree in various styles (Unicode, ASCII, Compact).
    • Show statistics for included/matched files and directories in the tree.
  • Content Collation:
    • Concatenates the content of all selected files into a single output file.
    • Optionally display an approximated token/character count.
  • Snapshot Deconstruction:
    • A utility function to parse a generated snapshot file and extract the directory tree and file paths.

Installation

You can install Dirshot from PyPI:

pip install dirshot

Usage

Here are some examples of how to use Dirshot in your own Python scripts.

Example 1: Creating a Snapshot with Presets (Filter Mode)

This example creates a snapshot of a Python project, ignoring common virtual environment and build directories.

from dirshot import filter_project, LanguagePreset, IgnorePreset

filter_project(
    root_dir_param=".",
    output_file_name="project_snapshot.txt",
    language_presets=[LanguagePreset.PYTHON],
    ignore_presets=[
        IgnorePreset.PYTHON_ENV,
        IgnorePreset.NODE_MODULES,
        IgnorePreset.BUILD_ARTIFACTS,
    ],
    show_token_count=True,
)

Example 2: Searching for Keywords in a Project (Search Mode)

This example searches for the keywords "API" or "Controller" within .java and .js files.

from dirshot import find_in_project

find_in_project(
    root_dir_param="example_project",
    output_file_name="search_results.txt",
    search_keywords=["API", "Controller"],
    file_extensions_to_check=[".java", ".js"],
    ignore_dirs_in_path=["node_modules", "build"],
    search_file_contents=True,
    show_tree_stats=True,
)

Deconstructing a Snapshot

You can also parse a previously generated snapshot file to extract the directory structure and the list of included files.

from dirshot import deconstruct_snapshot

snapshot_data = deconstruct_snapshot("project_snapshot.txt")
print("Directory Tree:")
for line in snapshot_data["tree_lines"]:
    print(line)

print("\nIncluded Files:")
for file_path in snapshot_data["file_paths"]:
    print(file_path)

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on the project's GitHub repository.

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.1.0.tar.gz (13.9 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.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dirshot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 01a00ad086b834f727a1e78c60484ea7abd12c9cb0b39eadf37c0d547885f96d
MD5 73dafeaebe34302d1d3c175db6ed3770
BLAKE2b-256 d6b90ff1e86c9b6f01c57a4a2adaf23253e21eb6e0d8958a5fdd4ce569174d6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dirshot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ff0360c5acb04abc5939a6ff119f309dc4a269e06277b03b64064fbef1d11ca
MD5 e28ef595527b406ab01d916241d3b6c2
BLAKE2b-256 aac146823b150ccff4cf6a4ad547317dcac1c265a3ca95bcbe9eef572b91c388

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