You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use custom endpoint URL to use s3pathlib with Minio.
From the documentation below, I can see it is easy to change many parameters, but not the endpoint_url which is defined inside the client. And in resolve_s3_client, context.s3_client returns a new client so it is not possible to change its endpoint.
from s3pathlib import context
context.attach_boto_session(
boto3.session.Session(
region_name="us-east-1",
profile_name="my_aws_profile",
)
)
I would like to change the endpoint so I can use a self hosted minio instead of default AWS endpoint.
I think you can do that. Firstly the s3_client is cached by default, which means that it is a multable object, and you can custom it's endpoint after creation. Another method would be, explicitly create the boto session object using boto3.session.Session with the custom endpoint, and explicitly give it to bsm and s3pathlib.context.
from s3pathlib import context
import boto3
boto_ses = boto3.session.Session(...) # customize the endpoint
context.attach_boto_ses(boto_ses)
@sergun THIS FEATURE IS ALREADY SUPPORTED FROM 1.X.Y. Here's an sample code to show how to use s3pathlib to connect to cloudflare R2, using custom endpoint.
CreateAPITokenstep1.pngstep2.pngSampleCode# -*- coding: utf-8 -*-importjsonfrompathlibimportPathimportboto3froms3pathlibimportS3Path, contextpath=Path.home().joinpath(
".cloudflare",
"r2-account-token.json",
)
cred=json.loads(path.read_text())
token=cred["token"]
access_key=cred["access_key"]
secret_key=cred["secret_key"]
endpoint=cred["endpoint"]
s3_client=boto3.client(
service_name="s3",
endpoint_url=endpoint,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
region_name="auto",
)
context._s3_client=s3_clients3path=S3Path(f"s3://my-bucketdev/test.txt")
s3path.write_text("hello world")
print(s3path.read_text())
# or you can use s3path.write_text("hello world", bsm=s3_client)
Activity
MacHu-GWU commentedon May 10, 2023
I think you can do that. Firstly the s3_client is cached by default, which means that it is a multable object, and you can custom it's endpoint after creation. Another method would be, explicitly create the boto session object using boto3.session.Session with the custom endpoint, and explicitly give it to bsm and s3pathlib.context.
alspadoni commentedon Nov 26, 2024
The custom endpoint belongs to the client, not the session. Is it troublesome to add support for custom endpoint in context?
MacHu-GWU commentedon Mar 7, 2025
@alspadoni add support to this feature in 2.3.2. Now you can do
context.attach_s3_client(your_custom_s3_client)MacHu-GWU commentedon May 8, 2025
MARK THIS ISSUE CLOSED
sergun commentedon May 31, 2025
Just vote for this feature
MacHu-GWU commentedon May 31, 2025
@sergun THIS FEATURE IS ALREADY SUPPORTED FROM 1.X.Y. Here's an sample code to show how to use s3pathlib to connect to cloudflare R2, using custom endpoint.