Skip to content

About

πŸ” Fast, deterministic file discovery and reporting toolkit with a rich CLI, structured metadata, and NDJSON output for reliable automation.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

167 Commits

Folders and files

Repository files navigation

file-discovery

A Python library and CLI that discovers, classifies, and catalogues files by inspecting their content.

Why this project exists

Purpose

File Discovery provides a reusable module for scanning large, mixed file collections and producing a deterministic, structured catalogue suitable for downstream processing, analysis, or organisation.

Benefit to the user

Operators and engineers gain a reliable, content-aware inventory of their files without relying on naming conventions, directory layout, or file extensions. The streaming NDJSON output integrates into automation pipelines, while the companion file-report tool converts results to CSV for spreadsheet review.

Problem it solves

Unstructured file collections (videos, photos, music, documents, archives) are difficult to catalogue accurately. Extensions are often missing, misleading, or inconsistent. Manual classification is impractical at scale, and generic tools do not produce stable, machine-readable output for automation.

How it solves it (high level)

The module recursively traverses a directory tree, inspects file content using MIME detection and format-specific validators, assigns each file to a category, extracts metadata (size, timestamps, xxHash content hash), and emits deterministic NDJSON output. A separate file-report CLI transforms NDJSON to CSV with selectable fields.

Quick start

Prerequisites

  • Python 3.14 or later
  • libmagic (for MIME type detection)
  • uv

Install and setup

git clone https://github.com/stefaniuk/file-discovery.git
cd file-discovery
make env
uv run --python 3.14 pip install -e .

First run

file-discovery --root tests/file_discovery/integration/data

Expected output

NDJSON streams to STDOUT. No logs are emitted unless you enable them with --log-console or --log-file.

What it does

Features

  • Recursive directory scanning with deterministic ordering.
  • Content-based classification using MIME detection and format validators.
  • Metadata extraction (size, timestamps, xxHash content hash).
  • Streaming NDJSON output (one JSON object per line).
  • CSV export through file-report.
  • CLI and Python API entry points.

Non-goals

  • File system search, indexing, or query capabilities.
  • Deduplication or similarity detection.
  • Thumbnail generation or media transcoding.
  • Persistent storage (databases, object stores).
  • Interactive or graphical interfaces.
  • Configuration file parsing (command-line arguments only).

How it solves the problem

  1. Receive a root path via the CLI or API.
  2. Traverse the directory tree depth-first with deterministic ordering.
  3. Inspect file content using libmagic and format-specific validators.
  4. Extract metadata, including size, timestamps, and xxHash content hash.
  5. Emit NDJSON records for file and error entries as they are processed.
  6. Emit a summary record after traversal completes.
  7. Optionally convert NDJSON to CSV using file-report csv.

Key terms (canonical definitions):

  • Category: file type classification label.
  • Content hash: xxh64 digest used for stable content identification.
  • NDJSON: newline-delimited JSON output format.
  • Naming convention: CLI commands use hyphens; Python packages use underscores.

Definitions are in specs/001-file-discovery-classification/spec.md and specs/003-file-report/spec.md.

How to use

Configuration

The CLIs are configured entirely via command-line arguments. There are no configuration files.

See the CLI contracts for the full argument lists, exit codes, and I/O behaviour:

Naming convention: CLI commands use hyphens (file-discovery, file-report); Python packages use underscores (file_discovery, file_report).

Common workflows

# Scan a directory and stream NDJSON to STDOUT
file-discovery --root tests/file_discovery/integration/data

# Scan a directory and write NDJSON to a file
file-discovery --root /data --output /tmp/catalogue.ndjson

# Scan with logging to a separate file
file-discovery --root /data --output /tmp/catalogue.ndjson --log /tmp/file-discovery.log

# Enable console logging
file-discovery --root /data --log-console

# Convert NDJSON to CSV with default fields
file-discovery --root /data | file-report csv > report.csv

# Convert with specific fields
file-report csv --input /tmp/catalogue.ndjson --output report.csv --fields path,content_hash

Examples

Python API: scan a directory and write NDJSON.

from file_discovery.api import scan_directory
from file_discovery.config import ScanConfig

with open("catalogue.ndjson", "w", encoding="utf-8") as output:
    summary = scan_directory("/path/to/scan", output, config=ScanConfig())
    print(f"Processed {summary.processed_files} files")

Python API: convert NDJSON to CSV.

from file_report.api import convert_to_csv

with open("catalogue.ndjson", "r", encoding="utf-8") as input_file:
    with open("report.csv", "w", encoding="utf-8") as output_file:
        count = convert_to_csv(input_file, output_file, fields=["path", "content_hash"])
        print(f"Converted {count} records")

Troubleshooting

Exit codes and error handling are defined in the CLI contracts:

Documentation

Contributing

See the contributing guide for full guidelines on development workflow, code style, and pull request expectations.

Development setup

make env
make deps-dev
make config

Quality commands

Run the repository quality gates before submitting changes:

make lint
make test

Run make help to see the full list of targets.

Proposing changes

  1. Create a feature branch from main.
  2. Run make lint and make test before committing.
  3. Open a pull request with a clear description of changes.

Repository layout

Licence

MIT Licence - see LICENCE.md

About

πŸ” Fast, deterministic file discovery and reporting toolkit with a rich CLI, structured metadata, and NDJSON output for reliable automation.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages