Skip to main content

Flexibly extract information from S3 endpoint URL/URI strings

Project description

s3-endpoint-parse

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"] == "us-east-1"
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.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

s3_endpoint_parse-1.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file s3-endpoint-parse-1.1.0.tar.gz.

File metadata

  • Download URL: s3-endpoint-parse-1.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for s3-endpoint-parse-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0ae43dc8d8a68fd3d2c07c738d9b9d13a148678076f855d5bab3c59239162490
MD5 65c9e3d0a6c13f96e1d2d14806e0f554
BLAKE2b-256 98e64828ddc7db183b083f0934083db7bbb39bb19a9fd4f7ba3b333f336b22c3

See more details on using hashes here.

Provenance

File details

Details for the file s3_endpoint_parse-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for s3_endpoint_parse-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17e4b2049dc0ea1a70c88e0f5101dc4181715f338a2529dc7195f2556e91a513
MD5 94a6c6ec15d31aa920d0ff97f80adbb5
BLAKE2b-256 c9ffbdd47a90aa6f7a186cc63773103eefc6300aac13e156af47c8b3bd91903d

See more details on using hashes here.

Provenance

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