Skip to main content

Flexibly extract information from S3 endpoint URL/URI strings

Project description

s3-endpoint-parse

PyPI version Supported Version Code style: black Tests

Flexibly parses well-formed S3 URL/URIs, including legacy formats and new fips / dualstack formats, and for Chinese (中国) regions.

Returns a dictionary describing the endpoint:

{
    "match": bool,  # True if library matched
    "protocol": string,  # May be empty
    "bucket": string,  # Set if match is True
    "key": string,  # May be empty
    "region": string,  # May be empty
}

API

def parse(url: string) -> dict

Primary export, parses input and returns documented dictionary.

Examples

from s3_endpoint_parse import parse

# All below:  s3["match"] is True
s3 = parse("https://s3.amazonaws.com/my-bucket/my/cool/file.png")

assert s3["protocol"] == "https"
assert s3["bucket"] == "my-bucket"
assert s3["region"] == ""
assert s3["key"] == "my/cool/file.png"


s3 = parse("s3://my-bucket.s3.us-east-1.amazonaws.com.cn/my/cool/file.png")

assert s3["protocol"] == "s3"
assert s3["bucket"] == "my-bucket"
assert s3["region"] == "us-east-1"
assert s3["key"] == "my/cool/file.png"


s3 = parse("http://my-bucket.s3-us-east-1.amazonaws.com/my/cool/file.png")

assert s3["protocol"] == "http"
assert s3["bucket"] == "my-bucket"
assert s3["region"] == "us-east-1"
assert s3["key"] == "my/cool/file.png"


s3 = parse(
    "https://my-bucket.s3-fips.dualstack.us-east-1.amazonaws.com/my/cool/file.png"
)

assert s3["protocol"] == "https"
assert s3["bucket"] == "my-bucket"
assert s3["region"] == "us-east-1"
assert s3["key"] == "my/cool/file.png"

See many more examples in the /tests/ folder

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

s3-endpoint-parse-1.1.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

s3_endpoint_parse-1.1.1-py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page