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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: s3-endpoint-parse-1.1.1.tar.gz
  • Upload date:
  • Size: 3.0 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.1.tar.gz
Algorithm Hash digest
SHA256 fab00c749d7648968779238896d3ae6c093732635645e64c2689606eb9310e1c
MD5 ef50e5427cd95d614e81c524d1ce4c2c
BLAKE2b-256 38b3acfde610d65830d6a0ba43adb044fc17e8206b318dddc985c606615ac01f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for s3_endpoint_parse-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4636e41d4ef81114bf7efc24668e43c4a13babfee9a0fc5529e9f27d2fac240b
MD5 d093c3097eb4b5eeb2e2af882aa63b25
BLAKE2b-256 175b7e03ddc4f31be333ef6165eb9aff2c1ccf1b429bc29784e1493a91335fa2

See more details on using hashes here.

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