upload#

Upload file from local to s3.

class s3pathlib.core.upload.UploadAPIMixin[source]#

A mixin class that implements upload method.

upload_file(path: str | Path | Path, overwrite: bool = False, extra_args: dict = None, callback: callable = None, config=None, bsm: BotoSesManager | None = None)[source]#

Upload a file from local file system to targeted S3 path

Example:

>>> s3path = S3Path("bucket", "artifacts", "deployment.zip")
>>> s3path.upload_file(path="/tmp/build/deployment.zip", overwrite=True)
Parameters:
  • path – absolute path of the file on the local file system you want to upload

  • overwrite – if False, non of the file will be upload / overwritten if any of target s3 location already taken.

New in version 1.0.1.

upload_dir(local_dir: str | Path | Path, pattern: str = '**/*', overwrite: bool = False, bsm: BotoSesManager | None = None) int[source]#

Upload a directory on local file system and all sub-folders, files to a S3 prefix (logical directory)

Example:

>>> s3path = S3Path("bucket", "datalake", "orders/")
>>> s3path.upload_dir(path="/data/orders", overwrite=True)
Parameters:
  • local_dir – absolute path of the directory on the local file system you want to upload

  • pattern – linux styled glob pattern match syntax. see this official reference https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob for more details

  • overwrite – if False, non of the file will be upload / overwritten if any of target s3 location already taken.

Returns:

number of files uploaded

New in version 1.0.1.