s3.make_s3_upath()
Build an S3 UPath with the shared retry policy.
Usage
s3.make_s3_upath(
path,
*,
anon=False,
profile=None,
key=None,
secret=None,
token=None,
region=None,
endpoint_url=None,
request_checksum_calculation="when_required",
response_checksum_validation="when_required",
client_kwargs=None
)Parameters
path: str-
S3 URI or prefix, e.g.
"s3://my-bucket/some/key.tif". Thes3protocol is forced, so a bare"my-bucket/key"also works. anon: bool = False-
Whether to use an anonymous connection (public buckets only). If
False, usesprofile, thekey/secretgiven, or boto’s default credential resolver. Mirrorss3fs.S3FileSystem’sanon. profile: str = None-
Named AWS configuration profile to use for this path. The profile name is stored on the path and used independently by both s3fs and Rasterio. May be combined with
endpoint_urlfor S3-compatible stores, but not withanon=Trueor explicitkey,secret, ortoken. Setting a profile explicitly makes boto skip its environment-variable credential provider on both layers, so such a path can never be signed by ambientAWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEYvalues – which is what makes profiles the safer way to authenticate here. key: str = None-
If not anonymous, use this access key ID, if specified. Mutually exclusive with
aws_access_key_idinclient_kwargs. secret: str = None-
If not anonymous, use this secret access key, if specified. Mutually exclusive with
aws_secret_access_keyinclient_kwargs. token: str = None-
If not anonymous, use this security token, if specified, for temporary/STS credentials.
region: str = None-
AWS region name. Relevant for region-scoped AWS-native buckets.
endpoint_url: str = None-
S3-compatible endpoint URL. Omit for AWS-native S3.
request_checksum_calculation: str = "when_required"-
boto3 >=1.36 checksum behavior.
"when_required"avoids thex-amz-checksum-*trailers that some S3-compatible gateways (e.g. Ceph) reject; it’s a safe default even for gateways not known to need it. response_checksum_validation: str = "when_required"-
boto3 >=1.36 checksum behavior.
"when_required"avoids thex-amz-checksum-*trailers that some S3-compatible gateways (e.g. Ceph) reject; it’s a safe default even for gateways not known to need it. client_kwargs: dict = None-
Extra kwargs forwarded to the underlying botocore client. Defaults to
{"endpoint_url": endpoint_url}.regionis injected here asregion_name. Credentials passed here (CLIENT_CREDENTIAL_KEYS) reach s3fs only, never s3_env(), so they are rejected alongsideanon=Trueandprofilerather than silently signing the two layers differently.
Returns
UPath-
An S3
UPathconfigured withS3_MAX_ATTEMPTSbotocore retries inS3_RETRY_MODEmode, on top of the s3fs-level retry handler registered by this module. Pair it with s3_env() for raster I/O.
Raises
ValueError-
If
anon=Trueis combined with a profile or credentials, if a profile is combined with explicitkey,secret,token, or credentials inclient_kwargs, or ifprofileis an empty string.
Examples
Anonymous access to a public bucket::
path = make_s3_upath(
"s3://copernicus-dem-30m/x.tif", region="eu-central-1", anon=True
)
Signed access via boto’s credential resolver, with no explicit key pair::
path = make_s3_upath("s3://my-private-bucket/x.tif")
Per-path profile selection, including for an S3-compatible endpoint::
path = make_s3_upath(
"s3://my-bucket/x.tif",
profile="research",
endpoint_url="https://objects.example.org",
)