Skip to main content

Deep storage auditing for Google Drive โ€” part of the Docto Trace suite.

Project description

๐Ÿ” docto-trace-storage

Deep storage auditing for Google Drive.
Part of the Docto Trace open-source suite.


What is this?

docto-trace-storage maps the "digital chaos" inside your Google Drive. It recursively traverses your entire storage, calculates the true size of every folder (something the native Drive UI doesn't show), detects zombie files that haven't been touched in years, and surfaces duplicate content wasting your quota โ€” all from your own machine, never touching Docto servers.

Read-Only, always. The tool never modifies or deletes files. It only observes and reports.

Your data stays local. The Drive API is called directly from your machine. No data passes through any Docto infrastructure.


Features

Feature Status
Google Drive OAuth2 authentication โœ… v0.1
Service Account support โœ… v0.1
Async recursive folder traversal โœ… v0.1
True cumulative folder sizes โœ… v0.1
Top-N largest folders (root excluded) โœ… v0.1
Deep folder detection โœ… v0.1
report.json export (strict Pydantic schema) โœ… v0.1
Rich terminal summary โœ… v0.1
๐ŸงŸ Zombie file detection (stale > N months) โœ… v0.2
โ™ป๏ธ Content deduplication (MD5 + fallback) โœ… v0.2
Duplicate file path tracing โœ… v0.2
Actionable remediation action_plan โœ… v0.2
Bundled credentials (zero-setup for end users) โœ… v0.2
Bring Your Own Credentials (setup wizard) โœ… v0.2
login / logout auth lifecycle โœ… v0.2

Trust & Privacy

Are you handing your private Drive to a stranger's app? No.

  1. Read-only scopes only โ€” the OAuth2 consent grants only drive.readonly and drive.metadata.readonly. The API physically cannot write, move, or delete anything.
  2. 100% local execution โ€” your credentials, your token, and your Drive data never leave your machine. There is no Docto backend, no telemetry, no analytics.
  3. Bring Your Own Credentials โ€” you can create your own Google Cloud project and register your own OAuth2 app in ~5 minutes. Your token is then issued against your GCP project, which you control fully.
# Create your own GCP credentials (interactive wizard)
docto-trace setup

See Using Your Own Google Cloud Credentials for the full guide.


Installation

For end users (zero setup)

The package ships with Docto's OAuth2 credentials bundled inside. Install from PyPI and scan โ€” the browser consent screen is the only step needed.

# Install from PyPI
pip install docto-trace-storage

# Scan immediately โ€” no credentials.json needed
docto-trace scan

From source (contributors / developers)

git clone https://github.com/Docto-Studio/docto-trace-storage.git
cd docto-trace-storage

# Install editable with dev tools
pip install -e ".[dev]"

Build your own wheel

python -m build --wheel
# โ†’ dist/docto_trace_storage-0.2.0-py3-none-any.whl

Requirements: Python 3.10+


Quick Start

# Check version
docto-trace --version      # โ†’ docto-trace-storage v0.2.0

# Option A โ€” Zero setup (uses bundled Docto credentials)
docto-trace scan            # browser opens for OAuth2 consent on first run

# Option B โ€” Full control (your own GCP project)
docto-trace setup           # guided 4-step wizard
docto-trace login           # authenticate
docto-trace scan            # run audit
docto-trace logout          # clear session

CLI Reference

docto-trace --version / -v

docto-trace --version   # docto-trace-storage v0.2.0
docto-trace -v          # same

docto-trace setup

Interactive 4-step wizard to create your own Google Cloud project and OAuth2 credentials. Run this once if you want full control over the app registration.

docto-trace setup
docto-trace setup --output ~/my-creds.json

docto-trace login

Authenticate with Google Drive and cache the token locally. Subsequent commands reuse the cached token silently.

docto-trace login
docto-trace login --credentials ./my-credentials.json
docto-trace login --service-account ./sa-key.json   # skip browser flow

docto-trace logout

Delete the cached token. The next scan or login will trigger a fresh browser flow.

docto-trace logout
docto-trace logout --revoke     # also revoke on Google's servers

docto-trace scan

The core command. Traverses Google Drive, runs all audits, and produces report.json.

# Full scan with defaults
docto-trace scan

# Narrow to a specific folder by Drive ID
docto-trace scan --root-id 1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms

# Cap depth, show top 20, custom output dir
docto-trace scan --max-depth 5 --top 20 --output ./reports/

# Zombie threshold: flag files not modified in 12 months (default: 24)
docto-trace scan --stale-threshold 12

# Use your own credentials file
docto-trace scan --credentials ./my-credentials.json

# Use a service account (no browser flow)
docto-trace scan --service-account ./sa-key.json
Flag Default Description
--root-id / -r root Drive folder ID to start from
--max-depth / -d unlimited Max folder depth to traverse
--top / -n 10 Top-N largest folders to show
--deep-threshold 5 Depth to flag as "deep"
--stale-threshold / -S 24 Months without modification = zombie
--credentials / -c credentials.json OAuth2 credentials file
--output / -o output/ Directory for report.json
--service-account / -s (none) Service account key path

Terminal Output Example

๐Ÿ” Authenticating with Google Driveโ€ฆ
โ„น๏ธ  Using Docto bundled credentials. Run docto-trace setup to use your own.
๐ŸŒ Opening browser for Google Drive authorizationโ€ฆ  โ† first run only

๐Ÿ” Scanning: My Drive
โ ™ Traversing foldersโ€ฆ [00:18]

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿ“ฆ Storage Overview โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Root:          My Drive
  Total files:   14,832
  Total folders: 1,204
  Total size:    48.3 GB
  Max depth:     9

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿ† Top 10 Largest Folders โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 Rank  Folder     Path              Files    Size
 1     Projects   My Drive/Projects 8,241    31.2 GB
 2     Archive    My Drive/Archive  3,102    10.5 GB

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐ŸงŸ Zombie Files (381 stale) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 File             Path                             Last Modified  Size
 old_invoice.pdf  My Drive/Finance/old_invoice.pdf  2020-01-15    2.1 MB

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ™ป๏ธ  Duplicate Groups (70 groups ยท 104 MB wasted) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 Fingerprint       Path                                  Size/copy  Wasted
 c8cd4fe0ab7a7fe8โ€ฆ My Drive/Backup/8CDA554Bโ€ฆmov          12.0 MB    12.0 MB
 (2 copies)        My Drive/Photos/8CDA554Bโ€ฆmov

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โœ… Report saved โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Output: output/report.json

Report Schema (v0.2.0)

The output report.json follows the HealthReport Pydantic schema:

{
  "schema_version": "0.2.0",
  "generated_at": "2026-03-23T10:00:00Z",
  "storage_tree": { "root_name": "My Drive", "total_files": 14832, "total_size_bytes": 51876044800 },
  "insights": {
    "top_folders": [...],
    "deep_folders": [...]
  },
  "zombies": [
    { "file_id": "...", "name": "old_invoice.pdf", "path": "My Drive/Finance/old_invoice.pdf",
      "last_modified": "2020-01-15T10:30:00Z", "size_bytes": 2202009, "reason": "stale" }
  ],
  "duplicates": [
    { "fingerprint": "c8cd4fe0โ€ฆ", "files": ["id1", "id2"],
      "file_names": ["invoice_final.pdf", "invoice_copy.pdf"],
      "file_paths": ["My Drive/Docs/invoice_final.pdf", "My Drive/Backup/invoice_copy.pdf"],
      "size_bytes_per_copy": 2097152, "wasted_bytes": 2097152 }
  ],
  "action_plan": [
    { "severity": "warning",  "category": "zombie",    "description": "..." },
    { "severity": "critical", "category": "duplicate", "description": "..." }
  ]
}

Deduplication strategy:

  • Primary key โ€” md5Checksum from the Drive API (binary files: PDFs, images, Office docs)
  • Fallback key โ€” "<size_bytes>:<normalized_name>" for Google-native files (Docs, Sheets, Slides)

Using Your Own Google Cloud Credentials

If you want full control over the OAuth2 app registration โ€” so your consent screen, quotas, and audit logs belong entirely to you โ€” run the setup wizard:

docto-trace setup

It walks you through 4 steps, opening each Google Cloud Console page in your browser:

  1. Create a GCP project โ€” gives you ownership of the app
  2. Enable the Google Drive API โ€” only the two read-only scopes
  3. Configure the OAuth2 consent screen โ€” add yourself as a test user
  4. Download credentials.json โ€” the wizard validates it locally

Then authenticate with your own credentials:

docto-trace login --credentials ./credentials.json
docto-trace scan  --credentials ./credentials.json

You can revoke access at any time from Google Cloud Console โ†’ Credentials, independently of the Docto project.


Configuration

All settings can be overridden with environment variables prefixed DOCTO_TRACE_, or in a .env file:

Variable Default Description
DOCTO_TRACE_CREDENTIALS_PATH credentials.json OAuth2 credentials file
DOCTO_TRACE_TOKEN_PATH token.json Cached token path
DOCTO_TRACE_SERVICE_ACCOUNT_PATH (none) Service account key path
DOCTO_TRACE_MAX_DEPTH (unlimited) Max folder nesting to traverse
DOCTO_TRACE_DEEP_FOLDER_THRESHOLD 5 Depth to flag as "deep"
DOCTO_TRACE_TOP_N 10 Top-N largest folders
DOCTO_TRACE_STALE_THRESHOLD_MONTHS 24 Zombie detection cutoff (months)
DOCTO_TRACE_OUTPUT_DIR output/ Report output directory
DOCTO_TRACE_PAGE_SIZE 1000 Drive API items per page

Development

make install    # Install with dev dependencies
make lint       # Lint with ruff
make fix        # Auto-fix lint issues
make test       # Run unit tests (no credentials needed)
make typecheck  # Run mypy

Tests run entirely offline โ€” no Google credentials required:

python -m pytest tests/ -v
# 48 passed in 0.18s

Architecture

docto_trace/
โ”œโ”€โ”€ cli.py                  # Typer root entry point
โ”œโ”€โ”€ config.py               # Pydantic settings (env-var overridable)
โ”œโ”€โ”€ data/
โ”‚   โ””โ”€โ”€ credentials.json    # Bundled Docto OAuth2 credentials (package resource)
โ”œโ”€โ”€ auth/
โ”‚   โ”œโ”€โ”€ google_drive.py     # OAuth2 + service account flow (bundled fallback)
โ”‚   โ””โ”€โ”€ token_store.py      # Token serialization
โ”œโ”€โ”€ connectors/
โ”‚   โ”œโ”€โ”€ base.py             # AbstractConnector interface
โ”‚   โ””โ”€โ”€ google_drive.py     # Drive API (async, paginated, thread-safe)
โ”œโ”€โ”€ engine/
โ”‚   โ”œโ”€โ”€ traversal.py        # Iterative BFS tree builder (bounded concurrency)
โ”‚   โ”œโ”€โ”€ analytics.py        # Phase 1: top-N, deep-folder analytics
โ”‚   โ””โ”€โ”€ auditor.py          # Phase 2: zombie detection + deduplication
โ”œโ”€โ”€ schemas/
โ”‚   โ”œโ”€โ”€ storage.py          # FileNode, FolderNode, StorageTree
โ”‚   โ””โ”€โ”€ report.py           # HealthReport, ZombieFile, DuplicateGroup, โ€ฆ
โ””โ”€โ”€ commands/
    โ”œโ”€โ”€ setup.py            # `docto-trace setup`  โ€” BYOC wizard
    โ”œโ”€โ”€ login.py            # `docto-trace login`  โ€” OAuth2 flow
    โ”œโ”€โ”€ logout.py           # `docto-trace logout` โ€” clear token
    โ”œโ”€โ”€ scan.py             # `docto-trace scan`   โ€” core audit command
    โ””โ”€โ”€ report.py           # `docto-trace report` โ€” extended report (v0.3)

Key design decisions:

  • Bundled credentials โ€” docto_trace/data/credentials.json is shipped inside the wheel via importlib.resources, enabling zero-setup for end users. Technical users override with --credentials or docto-trace setup.
  • Schema-first โ€” all data models defined in Pydantic before any logic is written; report.json is machine-readable by other Docto modules.
  • Pure audit functions โ€” analytics.py and auditor.py are pure functions with no I/O; trivially unit-testable without credentials.
  • Iterative BFS traversal โ€” avoids Python stack overflows on large Drives; bounded to MAX_CONCURRENT=20 parallel API calls via asyncio.Semaphore.
  • Thread-safe HTTP โ€” each thread-pool worker gets its own httplib2.Http via threading.local, preventing socket corruption.

Roadmap

Version Focus
v0.1 Structural mapping โ€” folder sizes, deep nesting
v0.2 Data hygiene โ€” zombie detection, deduplication, bundled credentials, auth lifecycle
v0.3 Extended reporting โ€” owner analysis, sharing audit, cost estimation
v0.4 AI readiness score โ€” structured/unstructured ratio, naming entropy

License

Apache 2.0 ยฉ Docto Studio

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

docto_trace_storage-0.2.0.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

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

docto_trace_storage-0.2.0-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

Details for the file docto_trace_storage-0.2.0.tar.gz.

File metadata

  • Download URL: docto_trace_storage-0.2.0.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for docto_trace_storage-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2fb6408d4a9abc5a53d6ca3e5241d5841e5468e5f38468d496cb7145675aa5c6
MD5 95f5b862621bebd10f9756c786806cab
BLAKE2b-256 f0c1f78e9c84fcf5cbaf91148a4d9dfa32a8e16607b55840bad02ff6bfdc9762

See more details on using hashes here.

File details

Details for the file docto_trace_storage-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for docto_trace_storage-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38425ffbdb555ffde95505e23281c4df23c9ebef011d48f28e594c119636f3d5
MD5 d7ea1c30f777ca43737773487e5bc606
BLAKE2b-256 e515a0a920813f9bee14dd10dc8909b2c5bf5935d11e4e03ad058ccba5831ef8

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