Skip to main content

Pathy

Build codecov PyPI - Version Code style: black

Pathy is a practical Python package with type annotations tailored for managing Cloud Bucket storage through a Path-like interface. It has an intuitive API and supports your favorite cloud providers, facilitating file transfers between local systems and remote buckets. Ideal for seasoned developers, Pathy enables smooth local file system work during development, transitioning effortlessly to live APIs for deployment. It also simplifies converting bucket blobs into local files, offers an option for local file caching, and has a familiar CLI interface pathy.

💾 Installation

You can install pathy from pip:

Features Install Command
Google Cloud Storage pip install pathy[gcs]
Amazon S3 pip install pathy[s3]
Azure pip install pathy[azure]

🚀 Quickstart

Here's a quick run-down of how to get started offline if you intend to use Google Cloud Storage buckets when you ship.

from pathy import Pathy, use_fs

# Use the local file-system for quicker development
use_fs()

# Create a bucket
Pathy("gs://my_bucket").mkdir(exist_ok=True)

# An excellent blob
greeting = Pathy(f"gs://my_bucket/greeting.txt")

# But it doesn't exist yet
assert not greeting.exists()

# Create it by writing some text
greeting.write_text("Hello World!")

# Now it exists
assert greeting.exists()

# Delete it
greeting.unlink()

# Now it doesn't
assert not greeting.exists()

🔐 Setup Credentials

For most cloud operations, you'll need credentials. Here's how to configure your credentials based on the supported cloud providers.

Google Cloud Storage

Google recommends using a JSON credentials file, which you can specify by path:

from google.oauth2 import service_account
from pathy import set_client_params

credentials = service_account.Credentials.from_service_account_file("./my-creds.json")
set_client_params("gs", credentials=credentials)

Amazon S3

S3 uses a JSON credentials file, which you can specify by path:

from pathy import set_client_params

set_client_params("s3", key_id="YOUR_ACCESS_KEY_ID", key_secret="YOUR_ACCESS_SECRET")

Azure

Azure blob storage can be passed a connection_string:

from pathy import set_client_params

set_client_params("azure", connection_string="YOUR_CONNECTION_STRING")

or a BlobServiceClient instance:

from azure.storage.blob import BlobServiceClient
from pathy import set_client_params

service: BlobServiceClient = BlobServiceClient.from_connection_string(
    "YOUR_CONNECTION_STRING"
)
set_client_params("azure", service=service)

🧪 Development

Pathy uses uv for dependency management.

# Install dependencies
uv sync

# Run local tests (no cloud credentials needed)
uv run pytest

# Run a single test
uv run pytest pathy/_tests/test_pathy.py::test_name -x

# Run with cloud provider tests (requires env vars)
uv run pytest --run-gcs     # GCS_CREDENTIALS
uv run pytest --run-s3      # PATHY_S3_ACCESS_ID + PATHY_S3_ACCESS_SECRET
uv run pytest --run-azure   # PATHY_AZURE_CONNECTION_STRING

# Lint
uv run mypy pathy
uv run flake8 pathy
uv run black pathy --check

# Auto-format
uv run black pathy
uv run isort pathy

♻️ Semantic Versioning

Before Pathy reaches v1.0 the project is not guaranteed to have a consistent API, which means that types and classes may move around or be removed. That said, we try to be predictable when it comes to breaking changes, so the project uses semantic versioning to help users avoid breakage.

Specifically, new releases increase the patch semver component for new features and fixes, and the minor component when there are breaking changes. If you don't know much about semver strings, they're usually formatted {major}.{minor}.{patch} so increasing the patch component means incrementing the last number.

Consider a few examples:

From Version To Version Changes are Breaking
0.2.0 0.2.1 No
0.3.2 0.3.6 No
0.3.1 0.3.17 No
0.2.2 0.3.0 Yes

If you are concerned about breaking changes, you can pin the version in your requirements so that it does not go beyond the current semver minor component, for example if the current version was 0.11.0:

pathy>=0.11.0,<0.12.0

📖 API

Pathy

Pathy(self, paths)

Subclass of PathBase that works with bucket APIs.

exists

Pathy.exists(self: 'Pathy') -> bool

Returns True if the path points to an existing bucket, blob, or prefix.

fluid

Pathy.fluid(
    path_candidate: Union[str, Pathy, PathlibPathEx],
) -> Union[Pathy, PathlibPathEx]

Infer either a Pathy or pathlib.Path from an input path or string.

The returned type is a union of the potential FluidPath types and will type-check correctly against the minimum overlapping APIs of all the input types.

If you need to use specific implementation details of a type, "narrow" the return of this function to the desired type, e.g.

from pathlib import Path
from pathy import FluidPath, Pathy

fluid_path: FluidPath = Pathy.fluid("gs://my_bucket/foo.txt")
# Narrow the type to a specific class
assert isinstance(fluid_path, Pathy), "must be Pathy"
# Use a member specific to that class
assert fluid_path.prefix == "foo.txt/"

# Or use a file-system path
posix_path: FluidPath = Pathy.fluid("/tmp/foo.txt")
assert isinstance(posix_path, Path), "must be pathlib.Path"

from_bucket

Pathy.from_bucket(bucket_name: str, scheme: str = 'gs') -> 'Pathy'

Initialize a Pathy from a bucket name. This helper adds a trailing slash and the appropriate prefix.

from pathy import Pathy

assert str(Pathy.from_bucket("one")) == "gs://one/"
assert str(Pathy.from_bucket("two")) == "gs://two/"

glob

Pathy.glob(
    self: 'Pathy',
    pattern: str,
    case_sensitive: Optional[bool] = None,
    follow_symlinks: Optional[bool] = None,
) -> Generator[Pathy, NoneType, NoneType]

Perform a glob match relative to this Pathy instance, yielding all matched blobs.

is_dir

Pathy.is_dir(self: 'Pathy', follow_symlinks: bool = True) -> bool

Determine if the path points to a bucket or a prefix of a given blob in the bucket.

Returns True if the path points to a bucket or a blob prefix. Returns False if it points to a blob or the path doesn't exist.

is_file

Pathy.is_file(self: 'Pathy', follow_symlinks: bool = True) -> bool

Determine if the path points to a blob in the bucket.

Returns True if the path points to a blob. Returns False if it points to a bucket or blob prefix, or if the path doesn’t exist.

ls

Pathy.ls(self: 'Pathy') -> Generator[BlobStat, NoneType, NoneType]

List blob names with stat information under the given path.

This is considerably faster than using iterdir if you also need the stat information for the enumerated blobs.

Yields BlobStat objects for each found blob.

mkdir

Pathy.mkdir(
    self,
    mode: int = 511,
    parents: bool = False,
    exist_ok: bool = False,
) -> None

Create a bucket from the given path. Since bucket APIs only have implicit folder structures (determined by the existence of a blob with an overlapping prefix) this does nothing other than create buckets.

If parents is False, the bucket will only be created if the path points to exactly the bucket and nothing else. If parents is true the bucket will be created even if the path points to a specific blob.

The mode param is ignored.

Raises FileExistsError if exist_ok is false and the bucket already exists.

open

Pathy.open(
    self: 'Pathy',
    mode: str = 'r',
    buffering: int = 8192,
    encoding: Optional[str] = None,
    errors: Optional[str] = None,
    newline: Optional[str] = None,
) -> IO[Any]

Open the given blob for streaming. This delegates to the smart_open library that handles large file streaming for a number of bucket API providers.

owner

Pathy.owner(self: 'Pathy') -> Optional[str]

Returns the name of the user that owns the bucket or blob this path points to. Returns None if the owner is unknown or not supported by the bucket API provider.

rename

Pathy.rename(
    self: 'Pathy',
    target: Union[str, pathlib_abc.PurePathBase],
) -> 'Pathy'

Rename this path to the given target.

If the target exists and is a file, it will be replaced silently if the user has permission.

If path is a blob prefix, it will replace all the blobs with the same prefix to match the target prefix.

replace

Pathy.replace(
    self: 'Pathy',
    target: Union[str, pathlib_abc.PurePathBase],
) -> 'Pathy'

Renames this path to the given target.

If target points to an existing path, it will be replaced.

resolve

Pathy.resolve(self, strict: bool = False) -> 'Pathy'

Resolve the given path to remove any relative path specifiers.

from pathy import Pathy

path = Pathy("gs://my_bucket/folder/../blob")
assert path.resolve() == Pathy("gs://my_bucket/blob")

rmdir

Pathy.rmdir(self: 'Pathy') -> None

Removes this bucket or blob prefix. It must be empty.

samefile

Pathy.samefile(
    self: 'Pathy',
    other_path: Union[str, bytes, int, pathlib_abc.PathBase],
) -> bool

Determine if this path points to the same location as other_path.

stat

Pathy.stat(self: 'Pathy', follow_symlinks: bool = True) -> pathy.BlobStat

Returns information about this bucket path.

to_local

Pathy.to_local(
    blob_path: Union[Pathy, str],
    recurse: bool = True,
) -> pathlib.Path

Download and cache either a blob or a set of blobs matching a prefix.

The cache is sensitive to the file updated time, and downloads new blobs as their updated timestamps change.

touch

Pathy.touch(self: 'Pathy', mode: int = 438, exist_ok: bool = True) -> None

Create a blob at this path.

If the blob already exists, the function succeeds if exist_ok is true (and its modification time is updated to the current time), otherwise FileExistsError is raised.

unlink

Pathy.unlink(self: 'Pathy') -> None

Delete a link to a blob in a bucket.

BlobStat

BlobStat(
    self,
    name: str,
    size: Optional[int],
    last_modified: Optional[int],
) -> None

Stat for a bucket item

use_fs

use_fs(
    root: Optional[str, pathlib_abc.PathBase, pathy.PathlibPathEx, bool] = None,
) -> Optional[pathy.BucketClientFS]

Use a path in the local file-system to store blobs and buckets.

This is useful for development and testing situations, and for embedded applications.

get_fs_client

get_fs_client() -> Optional[pathy.BucketClientFS]

Get the file-system client (or None)

use_fs_cache

use_fs_cache(
    root: Optional[str, pathlib_abc.PathBase, pathy.PathlibPathEx, bool] = None,
) -> Optional[pathy.PathlibPathEx]

Use a path in the local file-system to cache blobs and buckets.

This is useful for when you want to avoid fetching large blobs multiple times, or need to pass a local file path to a third-party library.

get_fs_cache

get_fs_cache() -> Optional[pathy.PathlibPathEx]

Get the folder that holds file-system cached blobs and timestamps.

set_client_params

set_client_params(scheme: str, kwargs: Any) -> None

Specify args to pass when instantiating a service-specific Client object. This allows for passing credentials in whatever way your underlying client library prefers.

💻 CLI

Pathy command line interface. (v0.11.0)

Usage:

$ [OPTIONS] COMMAND [ARGS]...

Options:

  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

  • cp: Copy a blob or folder of blobs from one...
  • ls: List the blobs that exist at a given...
  • mv: Move a blob or folder of blobs from one...
  • rm: Remove a blob or folder of blobs from a...

cp

Copy a blob or folder of blobs from one bucket to another.

Usage:

$ cp [OPTIONS] FROM_LOCATION TO_LOCATION

Arguments:

  • FROM_LOCATION: [required]
  • TO_LOCATION: [required]

Options:

  • --help: Show this message and exit.

ls

List the blobs that exist at a given location.

Usage:

$ ls [OPTIONS] LOCATION

Arguments:

  • LOCATION: [required]

Options:

  • -l, --long: Print long style entries with updated time and size shown.
  • --help: Show this message and exit.

mv

Move a blob or folder of blobs from one path to another.

Usage:

$ mv [OPTIONS] FROM_LOCATION TO_LOCATION

Arguments:

  • FROM_LOCATION: [required]
  • TO_LOCATION: [required]

Options:

  • --help: Show this message and exit.

rm

Remove a blob or folder of blobs from a given location.

Usage:

$ rm [OPTIONS] LOCATION

Arguments:

  • LOCATION: [required]

Options:

  • -r, --recursive: Recursively remove files and folders.
  • -v, --verbose: Print removed files and folders.
  • --help: Show this message and exit.

Credits

Pathy is originally based on the S3Path project, which provides a Path interface for S3 buckets.

Metadata

Release files for pathy 0.14.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pathy 0.14.2
File Size Uploaded
pathy-0.14.2.tar.gz 168.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pathy 0.14.2
File Interpreter ABI Platform
pathy-0.14.2-py3-none-any.whl Python 3 none any Details

Total release size: 219.7 kB

Release files / pathy-0.14.2.tar.gz

Download URL pathy-0.14.2.tar.gz
Size 168.8 kB
Tags Source
SHA-256 checksum
How to use checksums
18e5bebae74d6a56e09ead1adc92d8794c1e7a33f45411c080f79ff2a4c31fae
BLAKE2b-256 checksum
How to use checksums
98c8adee48909db6e57affb31d571fbb5ba7a88446d2776c202a46da487f63f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 11, 2026.

Transparency log

Release files / pathy-0.14.2-py3-none-any.whl

Download URL pathy-0.14.2-py3-none-any.whl
Size 50.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61d225570906d33b18cd12a864cba7f100b246ef976102860f3224fa111e329a
BLAKE2b-256 checksum
How to use checksums
97a8b3ee9c9581547861b6536882ec718bc3461b26e9aeb7627fed755a774653
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.14.2 This release

2 release files

0.11.0

2 release files

0.10.3

2 release files

0.10.2

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.17

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page