Parse and Build Amazon S3 URLs

0.0.3 · active · verified Thu Apr 16

s3urls is a small, dependency-free Python library designed to parse and build Amazon S3 URLs. It provides utility functions to extract bucket names and keys from S3 URIs (e.g., `s3://bucket/key`) and HTTP/HTTPS S3 object URLs, as well as to construct such URLs. The current version is 0.0.3, with its last release in 2018, indicating a stable but infrequently updated project.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `s3urls` to parse various S3 URL formats (S3 URIs and HTTPS URLs) and how to build S3 URLs, including specifying the scheme, region, and style for HTTPS URLs.

from s3urls import parse_s3_url, build_s3_url

# Example 1: Parsing an S3 URI
s3_uri = 's3://my-bucket/path/to/object.txt'
parsed = parse_s3_url(s3_uri)
print(f"Parsed S3 URI - Bucket: {parsed['bucket']}, Key: {parsed['key']}")

# Example 2: Parsing an HTTPS virtual-hosted style URL
https_url = 'https://my-bucket.s3.us-east-1.amazonaws.com/another/file.csv'
parsed = parse_s3_url(https_url)
print(f"Parsed HTTPS URL - Bucket: {parsed['bucket']}, Key: {parsed['key']}, Region: {parsed['region']}")

# Example 3: Building an S3 URI
built_s3_uri = build_s3_url(bucket='my-new-bucket', key='data/results.json')
print(f"Built S3 URI: {built_s3_uri}")

# Example 4: Building an HTTPS virtual-hosted style URL with region
built_https_url = build_s3_url(bucket='my-other-bucket', key='images/pic.jpg', region='eu-west-1', scheme='https', style='virtual-host')
print(f"Built HTTPS URL: {built_https_url}")

view raw JSON →