MCPcopy Create free account
hub / github.com/apache/arrow / copy_files

Function copy_files

python/pyarrow/fs.py:190–262  ·  view source on GitHub ↗

Copy files between FileSystems. This functions allows you to recursively copy directories of files from one file system to another, such as from S3 to your local machine. Parameters ---------- source : string Source file path or URI to a single file or directory.

(source, destination,
               source_filesystem=None, destination_filesystem=None,
               *, chunk_size=1024*1024, use_threads=True)

Source from the content-addressed store, hash-verified

188
189
190def copy_files(source, destination,
191 source_filesystem=None, destination_filesystem=None,
192 *, chunk_size=1024*1024, use_threads=True):
193 """
194 Copy files between FileSystems.
195
196 This functions allows you to recursively copy directories of files from
197 one file system to another, such as from S3 to your local machine.
198
199 Parameters
200 ----------
201 source : string
202 Source file path or URI to a single file or directory.
203 If a directory, files will be copied recursively from this path.
204 destination : string
205 Destination file path or URI. If `source` is a file, `destination`
206 is also interpreted as the destination file (not directory).
207 Directories will be created as necessary.
208 source_filesystem : FileSystem, optional
209 Source filesystem, needs to be specified if `source` is not a URI,
210 otherwise inferred.
211 destination_filesystem : FileSystem, optional
212 Destination filesystem, needs to be specified if `destination` is not
213 a URI, otherwise inferred.
214 chunk_size : int, default 1MB
215 The maximum size of block to read before flushing to the
216 destination file. A larger chunk_size will use more memory while
217 copying but may help accommodate high latency FileSystems.
218 use_threads : bool, default True
219 Whether to use multiple threads to accelerate copying.
220
221 Examples
222 --------
223 Inspect an S3 bucket's files:
224
225 >>> s3, path = fs.FileSystem.from_uri(
226 ... "s3://registry.opendata.aws/roda/ndjson/")
227 >>> selector = fs.FileSelector(path)
228 >>> s3.get_file_info(selector)
229 [<FileInfo for 'registry.opendata.aws/roda/ndjson/index.ndjson':...]
230
231 Copy one file from S3 bucket to a local directory:
232
233 >>> fs.copy_files("s3://registry.opendata.aws/roda/ndjson/index.ndjson",
234 ... f"file:///{local_path}/index_copy.ndjson")
235
236 >>> fs.LocalFileSystem().get_file_info(str(local_path)+
237 ... '/index_copy.ndjson')
238 <FileInfo for '.../index_copy.ndjson': type=FileType.File, size=...>
239
240 Copy file using a FileSystem object:
241
242 >>> fs.copy_files("registry.opendata.aws/roda/ndjson/index.ndjson",
243 ... f"file:///{local_path}/index_copy.ndjson",
244 ... source_filesystem=fs.S3FileSystem())
245 """
246 source_fs, source_path = _resolve_filesystem_and_path(
247 source, source_filesystem

Callers 2

test_copy_filesFunction · 0.90

Calls 3

FileSelectorClass · 0.50
get_file_infoMethod · 0.45

Tested by 2

test_copy_filesFunction · 0.72