Skip to content

Providers

anyuri.providers.GSUri

Bases: AnyUri

URI for Google Cloud Storage resources.

Accepts both gs:// and https://storage.googleapis.com/ forms. Stores internally as HTTPS; as_uri() returns the gs:// form.

Examples:

>>> GSUri("gs://bucket/1.jpg")
GSUri("gs://bucket/1.jpg")
>>> GSUri("https://storage.googleapis.com/bucket/1.jpg")
GSUri("gs://bucket/1.jpg")

validate classmethod

validate(value)

Validate and return the appropriate AnyUri subclass for value.

Raises:

Type Description
UriSchemaError

if no registered type accepts the input.

Source code in src/anyuri/providers/_gcs.py
43
44
45
@classmethod
def validate(cls, value: Any) -> GSUri:
    return cls(cls._validate(value))

as_uri

as_uri()

Canonical URI form (e.g. gs://bucket/key for GCS).

Returns:

Type Description
str

The canonical URI string.

Source code in src/anyuri/providers/_gcs.py
47
48
def as_uri(self) -> str:
    return str(self).replace("https://storage.googleapis.com/", "gs://", 1)

anyuri.providers.S3Uri

Bases: AnyUri

URI for AWS S3 resources.

Accepts s3://, virtual-hosted HTTPS, and path-style HTTPS forms. Stores internally as virtual-hosted HTTPS; as_uri() returns s3://.

Examples:

>>> S3Uri("s3://bucket/key.jpg")
S3Uri("s3://bucket/key.jpg")
>>> S3Uri("https://bucket.s3.amazonaws.com/key.jpg")
S3Uri("s3://bucket/key.jpg")

validate classmethod

validate(value)

Validate and return the appropriate AnyUri subclass for value.

Raises:

Type Description
UriSchemaError

if no registered type accepts the input.

Source code in src/anyuri/providers/_s3.py
63
64
65
@classmethod
def validate(cls, value: Any) -> S3Uri:
    return cls(cls._validate(value))

as_uri

as_uri()

Canonical URI form (e.g. gs://bucket/key for GCS).

Returns:

Type Description
str

The canonical URI string.

Source code in src/anyuri/providers/_s3.py
67
68
69
70
71
def as_uri(self) -> str:
    # https://bucket.s3.amazonaws.com/key → s3://bucket/key
    p = urlparse(str(self))
    bucket = (p.hostname or "").split(".")[0]
    return f"s3://{bucket}{p.path}"

anyuri.providers.AzureUri

Bases: AnyUri

URI for Azure Blob Storage resources.

Accepts abfs://, abfss:// (ADLS Gen2), and HTTPS Blob Storage forms. Stores internally as HTTPS; as_uri() returns the abfs:// canonical form.

The ABFS format is: abfs://<container>@<account>.dfs.core.windows.net/<path>

Examples:

>>> AzureUri("abfs://container@account.dfs.core.windows.net/file.txt")
AzureUri("abfs://container@account.dfs.core.windows.net/file.txt")
>>> AzureUri("https://account.blob.core.windows.net/container/file.txt")
AzureUri("abfs://container@account.dfs.core.windows.net/file.txt")

validate classmethod

validate(value)

Validate and return the appropriate AnyUri subclass for value.

Raises:

Type Description
UriSchemaError

if no registered type accepts the input.

Source code in src/anyuri/providers/_azure.py
56
57
58
@classmethod
def validate(cls, value: Any) -> AzureUri:
    return cls(cls._validate(value))

as_uri

as_uri()

Canonical URI form (e.g. gs://bucket/key for GCS).

Returns:

Type Description
str

The canonical URI string.

Source code in src/anyuri/providers/_azure.py
60
61
62
63
64
65
66
67
68
69
def as_uri(self) -> str:
    # https://account.blob.core.windows.net/container/path/file
    # → abfs://container@account.dfs.core.windows.net/path/file
    p = urlparse(str(self))
    account = (p.hostname or "").split(".")[0]
    # path: /container/rest/of/path
    path_parts = p.path.lstrip("/").split("/", 1)
    container = path_parts[0]
    remaining = f"/{path_parts[1]}" if len(path_parts) > 1 else "/"
    return f"abfs://{container}@{account}.dfs.core.windows.net{remaining}"

anyuri.providers.R2Uri

Bases: AnyUri

URI for Cloudflare R2 resources.

Accepts r2://<account>/<bucket>/<key> and HTTPS R2 storage forms. Stores internally as HTTPS; as_uri() returns the r2:// form.

Examples:

>>> R2Uri("r2://accountid/bucket/key.jpg")
R2Uri("r2://accountid/bucket/key.jpg")
>>> R2Uri("https://accountid.r2.cloudflarestorage.com/bucket/key.jpg")
R2Uri("r2://accountid/bucket/key.jpg")

validate classmethod

validate(value)

Validate and return the appropriate AnyUri subclass for value.

Raises:

Type Description
UriSchemaError

if no registered type accepts the input.

Source code in src/anyuri/providers/_r2.py
48
49
50
@classmethod
def validate(cls, value: Any) -> R2Uri:
    return cls(cls._validate(value))

as_uri

as_uri()

Canonical URI form (e.g. gs://bucket/key for GCS).

Returns:

Type Description
str

The canonical URI string.

Source code in src/anyuri/providers/_r2.py
52
53
54
55
56
def as_uri(self) -> str:
    # https://accountid.r2.cloudflarestorage.com/bucket/key → r2://accountid/bucket/key
    p = urlparse(str(self))
    account = (p.hostname or "").split(".")[0]
    return f"r2://{account}{p.path}"

anyuri.providers.B2Uri

Bases: AnyUri

URI for Backblaze B2 resources.

Accepts b2://bucket/key and https://f<N>.backblazeb2.com/file/bucket/key. Always normalizes to the native b2:// form; the cluster number is discarded because it is not derivable from the bucket name alone.

Examples:

>>> B2Uri("b2://mybucket/key.jpg")
B2Uri("b2://mybucket/key.jpg")
>>> B2Uri("https://f003.backblazeb2.com/file/mybucket/key.jpg")
B2Uri("b2://mybucket/key.jpg")

validate classmethod

validate(value)

Validate and return the appropriate AnyUri subclass for value.

Raises:

Type Description
UriSchemaError

if no registered type accepts the input.

Source code in src/anyuri/providers/_b2.py
52
53
54
@classmethod
def validate(cls, value: Any) -> B2Uri:
    return cls(cls._validate(value))

as_uri

as_uri()

Canonical URI form (e.g. gs://bucket/key for GCS).

Returns:

Type Description
str

The canonical URI string.

Source code in src/anyuri/providers/_b2.py
56
57
def as_uri(self) -> str:
    return str(self)  # already in b2:// form