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"] == ""
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
Built Distribution
Close
Hashes for s3_endpoint_parse-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4636e41d4ef81114bf7efc24668e43c4a13babfee9a0fc5529e9f27d2fac240b |
|
MD5 | d093c3097eb4b5eeb2e2af882aa63b25 |
|
BLAKE2b-256 | 175b7e03ddc4f31be333ef6165eb9aff2c1ccf1b429bc29784e1493a91335fa2 |