Skip to main content

A CLI utility to manage Google Cloud Platform resource hierarchy paths.

Project description

gcpath

gcpath is a CLI utility to query Google Cloud Platform resource hierarchy paths. It helps you translate between GCP resource names (e.g., folders/12345) and human-readable paths (e.g., //example.com/department/team).

Why should I use gcpath?

  • familiar linux-like CLI
  • you can stay in the terminal for quick resource hierarchy lookups
  • no need to learn the complex gcloud interface
  • look-up only commands, so coding agents can't do harm using it

Features

  • Tree Visualization: View your hierarchy as a tree.
  • Recursive Listing: List all folders and projects in your organization as paths.
  • Path Resolution: Get the resource name (ID) for a given path.
  • Reverse Lookup: Get the path for a given resource name (ID).
  • Dual Mode:
    • Cloud Asset API (Default): Fast, bulk loading using GCP Cloud Asset Inventory.
    • Resource Manager API: Iterative loading using standard Resource Manager API (slower, but different permissions).

Roadmap

  • caching, for lightning fast lookups
  • diagram generation
  • entrypoint configuration (organization or folder)
  • IAM policies
  • other resources

Prerequisites

Authentication

gcpath uses Google Cloud Application Default Credentials (ADC).

  1. Install gcloud CLI.

  2. Authenticate:

    gcloud auth application-default login
    

Permissions

Ensure you have enough permissions on your entrypoint (organization or folder), see API modes.

Quick Start

# List all resources
gcpath ls

# List children of a specific folder
gcpath ls folders/123456789

# Find ID of a specific path
gcpath name //example.com/engineering

# Find path of a specific resource ID
gcpath path folders/123456789

# View tree rooted at organization
gcpath tree

# View tree rooted at folder
gcpath tree folders/123456789

# Generate a Mermaid diagram of the hierarchy
gcpath diagram

# Generate a D2 diagram scoped to a folder
gcpath diagram folders/123456789 --format d2

Usage

List Resources (ls)

List folders and projects. Defaults to the organization root.

gcpath ls [RESOURCE_NAME]

Options:

  • -l, --long: Show resource IDs and numbers (for projects).
  • -R, --recursive: List resources recursively.

Examples:

# List all organizations and their top-level children
gcpath ls

# List all contents of an organization recursively
gcpath ls -R

# List children of a specific folder
gcpath ls folders/123456789

Tree View (tree)

Visualize the resource hierarchy in a tree format.

gcpath tree [RESOURCE_NAME]

Options:

  • -L, --level N: Limit depth of the tree (no limit by default).
  • -i, --ids: Include resource IDs in the output.
  • -y, --yes: Skip confirmation prompts for large hierarchy loads.

Generate Diagram (diagram)

Generate a Mermaid or D2 diagram of the resource hierarchy.

gcpath diagram [RESOURCE_NAME]

Options:

  • -f, --format FORMAT: Output format: mermaid (default) or d2.
  • -L, --level N: Limit depth of the diagram.
  • -i, --ids: Include resource IDs in node labels.
  • -o, --output FILE: Write diagram to a file instead of stdout.
  • -y, --yes: Skip confirmation prompts for large hierarchy loads.

Examples:

# Generate Mermaid diagram of the full hierarchy
gcpath diagram

# Generate D2 diagram scoped to a folder
gcpath diagram folders/123456789 --format d2

# Save Mermaid diagram to a file with depth limit
gcpath diagram -L 3 -o hierarchy.mmd

# Include resource IDs in labels
gcpath diagram --ids

Get Resource Name (name)

Get the GCP resource name (e.g., folders/123) from a path:

gcpath name //example.com/engineering/backend

To get just the ID:

gcpath name --id //example.com/engineering/backend

Get Path (path)

Get the path from a resource name:

gcpath path folders/987654321

API Modes

gcpath supports two GCP APIs for loading resource hierarchy data:

Cloud Asset API (Default - Recommended)

Fast bulk loading via Cloud Asset Inventory. Recommended for most users.

# Use Cloud Asset API (default)
gcpath ls
gcpath ls --use-asset-api  # explicit
gcpath ls -u               # short form

Advantages:

  • 5-6x faster than Resource Manager API
  • Supports scoped loading (ls folders/123, tree folders/123)
  • Efficient for large hierarchies (1000+ folders)

Required Permissions:

  • cloudasset.assets.searchAllResources
  • resourcemanager.organizations.get
  • resourcemanager.folders.get
  • resourcemanager.projects.get

Setup: Requires Cloud Asset API to be enabled: gcloud services enable cloudasset.googleapis.com

Resource Manager API

Traditional recursive API calls. Use when Cloud Asset API is not available.

# Use Resource Manager API
gcpath ls --no-use-asset-api
gcpath ls -U  # short form

Advantages:

  • Works without Cloud Asset API enabled
  • Simpler permission model
  • Standard resourcemanager.* permissions

Required Permissions:

  • resourcemanager.organizations.get
  • resourcemanager.folders.list
  • resourcemanager.projects.list
  • resourcemanager.projects.get

Which Should I Use?

  • For most users: Use the default (Cloud Asset API) for best performance
  • If you get permission/API errors: Use -U flag for Resource Manager API

Acknowledgments

Thanks for xebia/gcp-path for the inspiration!

License

MIT

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

gcpath-0.4.0.tar.gz (80.5 kB view details)

Uploaded Source

Built Distribution

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

gcpath-0.4.0-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file gcpath-0.4.0.tar.gz.

File metadata

  • Download URL: gcpath-0.4.0.tar.gz
  • Upload date:
  • Size: 80.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gcpath-0.4.0.tar.gz
Algorithm Hash digest
SHA256 106f060827fdd2cbf89f61ccc3e580ee12c2854aaca9d90a3849d2150237c8d5
MD5 edfce72757dd660a483442a99b766fc1
BLAKE2b-256 e2ceb8a4d5177c644bd41ab8c7536bc5ee0292981d492103016e0a2de7ab05cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcpath-0.4.0.tar.gz:

Publisher: release.yml on tardigrde/gcpath

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gcpath-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: gcpath-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gcpath-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 721bb76badf7ca86cb96baf3a81af6f287c4e4dab3fb7716ca93cdfe84d1f277
MD5 392c692caebeea6bea924bcd45a0acde
BLAKE2b-256 36e2d81ce8b7c8e40eef63409a0a0474e3b93abf7be49f6aaa1070cf8ad03b36

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcpath-0.4.0-py3-none-any.whl:

Publisher: release.yml on tardigrde/gcpath

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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