| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/../api/../generated/pyarrow.fs.S3FileSystem.html | [Back] [Original] |
Bases: FileSystem
S3-backed FileSystem implementation
AWS access_key and secret_key can be provided explicitly.
If role_arn is provided instead of access_key and secret_key, temporary credentials will be fetched by issuing a request to STS to assume the specified role.
If neither access_key nor secret_key are provided, and role_arn is also not provided, then attempts to establish the credentials automatically. S3FileSystem will try the following methods, in order:
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables
configuration files such as ~/.aws/credentials and ~/.aws/config
for nodes on Amazon EC2, the EC2 Instance Metadata Service
Note: S3 buckets are special and the operations available on them may be limited or more expensive than desired.
When S3FileSystem creates new buckets (assuming allow_bucket_creation is True), it does not pass any non-default settings. In AWS S3, the bucket and all objects will be not publicly visible, and will have no bucket policies and no resource tags. To have more control over how buckets are created, use a different API to create them.
str, default NoneAWS Access Key ID. Pass None to use the standard AWS environment variables and/or configuration file.
str, default NoneAWS Secret Access key. Pass None to use the standard AWS environment variables and/or configuration file.
str, default NoneAWS Session Token. An optional session token, required if access_key and secret_key are temporary credentials from STS.
FalseWhether to connect anonymously if access_key and secret_key are None. If true, will not attempt to look up credentials using standard AWS configuration methods.
str, default NoneAWS Role ARN. If provided instead of access_key and secret_key, temporary credentials will be fetched by assuming this role.
str, default NoneAn optional identifier for the assumed role session.
str, default NoneAn optional unique identifier that might be required when you assume a role in another account.
int, default 900The frequency (in seconds) with which temporary credentials from an assumed role session will be refreshed.
str, default NoneAWS region to connect to. If not set, the AWS SDK will attempt to
determine the region using heuristics such as environment variables,
configuration profile, EC2 metadata, or default to us-east-1 when SDK
version <1.8. One can also use pyarrow.fs.resolve_s3_region() to
automatically resolve the region from a bucket name.
double, default NoneSocket read timeouts on Windows and macOS, in seconds. If omitted, the AWS SDK default value is used (typically 3 seconds). This option is ignored on non-Windows, non-macOS systems.
double, default NoneSocket connection timeout, in seconds. If omitted, the AWS SDK default value is used (typically 1 second).
str, default httpsS3 connection transport scheme.
str, default NoneOverride region with a connect string such as localhost:9000
TrueWhether file writes will be issued in the background, without blocking.
pyarrow.KeyValueMetadata, default NoneDefault metadata for open_output_stream. This will be ignored if non-empty metadata is passed to open_output_stream.
dict or str, default NoneIf a proxy is used, provide the options here. Supported options are: scheme (str: http or https; required), host (str; required), port (int; required), username (str; optional), password (str; optional). A proxy URI (str) can also be provided, in which case these options will be derived from the provided URI. The following are equivalent:
S3FileSystem(proxy_options='http://username:password@localhost:8020')
S3FileSystem(proxy_options={'scheme': 'http', 'host': 'localhost',
'port': 8020, 'username': 'username',
'password': 'password'})
FalseWhether to allow file-open methods to return before the actual open. This option may reduce latency as it decreases the number of round trips. The downside is failures such as opening a file in a non-existing bucket will only be reported when actual I/O is done (at worst, when attempting to close the file).
FalseWhether to allow directory creation at the bucket-level. This option may also be passed in a URI query parameter.
FalseWhether to allow directory deletion at the bucket-level. This option may also be passed in a URI query parameter.
falseWhether to check the directory existence before creating it. If false, when creating a directory the code will not check if it already exists or not. Its an optimization to try directory creation and catch the error, rather than issue two dependent I/O calls. If true, when creating a directory the code will only create the directory when necessary at the cost of extra I/O calls. This can be used for key/value cloud storage which has a hard rate limit to number of object mutation operations or scenarios such as the directories already exist and you do not have creation access.
S3RetryStrategy, default AwsStandardS3RetryStrategy(max_attempts=3)The retry strategy to use with S3; fail after max_attempts. Available strategies are AwsStandardS3RetryStrategy, AwsDefaultS3RetryStrategy.
FalseWhether to use virtual addressing of buckets. If true, then virtual addressing is always enabled. If false, then virtual addressing is only enabled if endpoint_override is empty. This can be used for non-AWS backends that only support virtual hosted-style access.
str, default NoneIf set, this should be the path of a file containing TLS certificates in PEM format which will be used for TLS verification.
Examples
>>> from pyarrow import fs
>>> s3 = fs.S3FileSystem(region='us-west-2')
>>> s3.get_file_info(fs.FileSelector(
... 'power-analysis-ready-datastore/power_901_constants.zarr/FROCEAN', recursive=True
... ))
[<FileInfo for 'power-analysis-ready-datastore/power_901_constants.zarr/FROCEAN/.zarray...
For usage of the methods see examples for LocalFileSystem().
Methods
|
|
|
Copy a file. |
|
Create a directory and subdirectories. |
|
Delete a directory and its contents, recursively. |
|
Delete a directory's contents, recursively. |
|
Delete a file. |
|
|
|
Create a new FileSystem from URI or Path. |
|
Get info for the given files. |
|
Move / rename a file or directory. |
|
Normalize filesystem path. |
|
Open an output stream for appending. |
|
Open an input file for random access reading. |
|
Open an input stream for sequential reading. |
|
Open an output stream for sequential writing. |
Attributes
Copy a file.
If the destination exists and is a directory, an error is returned. Otherwise, it is replaced.
Examples
>>> local.copy_file(path,
... local_path + '/pyarrow-fs-example_copy.dat')
Inspect the file info:
>>> local.get_file_info(local_path + '/pyarrow-fs-example_copy.dat')
<FileInfo for '/.../pyarrow-fs-example_copy.dat': type=FileType.File, size=4>
>>> local.get_file_info(path)
<FileInfo for '/.../pyarrow-fs-example.dat': type=FileType.File, size=4>
Create a directory and subdirectories.
This function succeeds if the directory already exists.
Delete a directory and its contents, recursively.
strThe path of the directory to be deleted.
Delete a directorys contents, recursively.
Like delete_dir, but doesnt delete the directory itself.
Create a new FileSystem from URI or Path.
Recognized URI schemes are file, mock, s3fs, gs, gcs, hdfs and viewfs. In addition, the argument can be a pathlib.Path object, or a string describing an absolute local path.
strURI-based path, for example: file:///some/local/path.
tuple of (FileSystem, str path)With (filesystem, path) tuple where path is the abstract path inside the FileSystem instance.
Examples
Create a new FileSystem subclass from a URI:
>>> uri = f'file:///{local_path}/pyarrow-fs-example.dat'
>>> local_new, path_new = fs.FileSystem.from_uri(uri)
>>> local_new
<pyarrow._fs.LocalFileSystem object at ...
>>> path_new
'/.../pyarrow-fs-example.dat'
Or from a s3 bucket:
>>> fs.FileSystem.from_uri("s3://usgs-landsat/collection02/")
(<pyarrow._s3fs.S3FileSystem object at ...>, 'usgs-landsat/collection02')
Or from an fsspec+ URI:
>>> fs.FileSystem.from_uri("fsspec+memory:///path/to/file")
(<pyarrow._fs.PyFileSystem object at ...>, '/path/to/file')
Get info for the given files.
Any symlink is automatically dereferenced, recursively. A non-existing or unreachable file returns a FileStat object and has a FileType of value NotFound. An exception indicates a truly exceptional condition (low-level I/O error, etc.).
FileSelector, path-like or list of path-likesEither a selector object, a path-like object or a list of path-like objects. The selectors base directory will not be part of the results, even if it exists. If it doesnt exist, use allow_not_found.
Examples
>>> local
<pyarrow._fs.LocalFileSystem object at ...>
>>> local.get_file_info(f"/{local_path}/pyarrow-fs-example.dat")
<FileInfo for '/.../pyarrow-fs-example.dat': type=FileType.File, size=4>
Move / rename a file or directory.
If the destination exists: - if it is a non-empty directory, an error is returned - otherwise, if it has the same type as the source, it is replaced - otherwise, behavior is unspecified (implementation-dependent).
Examples
Create a new folder with a file:
>>> local.create_dir('/tmp/other_dir')
>>> local.copy_file(path,'/tmp/move_example.dat')
Move the file:
>>> local.move('/tmp/move_example.dat',
... '/tmp/other_dir/move_example_2.dat')
Inspect the file info:
>>> local.get_file_info('/tmp/other_dir/move_example_2.dat')
<FileInfo for '/tmp/other_dir/move_example_2.dat': type=FileType.File, size=4>
>>> local.get_file_info('/tmp/move_example.dat')
<FileInfo for '/tmp/move_example.dat': type=FileType.NotFound>
Delete the folder: >>> local.delete_dir(/tmp/other_dir)
Normalize filesystem path.
Open an output stream for appending.
If the target doesnt exist, a new empty file is created.
Note
Some filesystem implementations do not support efficient appending to an existing file, in which case this method will raise NotImplementedError. Consider writing to multiple files (using e.g. the dataset layer) instead.
strThe source to open for writing.
str optional, default detectThe compression algorithm to use for on-the-fly compression. If detect and source is a file path, then compression will be chosen based on the file extension. If None, no compression will be applied. Otherwise, a well-known algorithm name must be supplied (e.g. gzip).
int optional, default NoneIf None or 0, no buffering will happen. Otherwise the size of the temporary write buffer.
dict optional, default NoneIf not None, a mapping of string keys to string values. Some filesystems support storing metadata along the file (such as Content-Type). Unsupported metadata keys will be ignored.
NativeFileExamples
Append new data to a FileSystem subclass with nonempty file:
>>> with local.open_append_stream(path) as f:
... f.write(b'+newly added')
12
Print out the content to the file:
>>> with local.open_input_file(path) as f:
... print(f.readall())
b'data+newly added'
Open an input file for random access reading.
strThe source to open for reading.
NativeFileExamples
Print the data from the file with open_input_file():
>>> with local.open_input_file(path) as f:
... print(f.readall())
b'data'
Open an input stream for sequential reading.
strThe source to open for reading.
str optional, default detectThe compression algorithm to use for on-the-fly decompression. If detect and source is a file path, then compression will be chosen based on the file extension. If None, no compression will be applied. Otherwise, a well-known algorithm name must be supplied (e.g. gzip).
int optional, default NoneIf None or 0, no buffering will happen. Otherwise the size of the temporary read buffer.
NativeFileExamples
Print the data from the file with open_input_stream():
>>> with local.open_input_stream(path) as f:
... print(f.readall())
b'data'
Open an output stream for sequential writing.
If the target already exists, existing data is truncated.
strThe source to open for writing.
str optional, default detectThe compression algorithm to use for on-the-fly compression. If detect and source is a file path, then compression will be chosen based on the file extension. If None, no compression will be applied. Otherwise, a well-known algorithm name must be supplied (e.g. gzip).
int optional, default NoneIf None or 0, no buffering will happen. Otherwise the size of the temporary write buffer.
dict optional, default NoneIf not None, a mapping of string keys to string values. Some filesystems support storing metadata along the file (such as Content-Type). Unsupported metadata keys will be ignored.
NativeFileExamples
>>> local = fs.LocalFileSystem()
>>> with local.open_output_stream(path) as stream:
... stream.write(b'data')
4
The AWS region this filesystem connects to.
The filesystems type name.
| Web Proxy Viewer | New URL | Original Page |