rclone-api 1.4.33__py2.py3-none-any.whl → 1.5.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,945 @@
1
+ Metadata-Version: 2.2
2
+ Name: rclone_api
3
+ Version: 1.5.1
4
+ Summary: rclone api in python
5
+ Home-page: https://github.com/zackees/rclone-api
6
+ License: BSD 3-Clause License
7
+ Keywords: rclone,api,python,fast,sftp,s3,backblaze
8
+ Classifier: Programming Language :: Python :: 3
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pyright>=1.1.393
13
+ Requires-Dist: python-dotenv>=1.0.0
14
+ Requires-Dist: certifi>=2025.1.31
15
+ Requires-Dist: psutil
16
+ Requires-Dist: boto3<=1.35.99,>=1.20.1
17
+ Requires-Dist: sqlmodel>=0.0.23
18
+ Requires-Dist: psycopg2-binary>=2.9.10
19
+ Requires-Dist: httpx>=0.28.1
20
+ Requires-Dist: download>=0.3.5
21
+ Requires-Dist: appdirs>=1.4.4
22
+ Dynamic: home-page
23
+
24
+ # rclone-api
25
+
26
+
27
+ ![perpetualmaniac_faster_400fd528-df15-4a04-8ad3-3cca786d7bca (2)](https://github.com/user-attachments/assets/65138e38-b115-447c-849a-4adbd27e4b67)
28
+
29
+
30
+ <!--
31
+ [![Linting](https://github.com/zackees/rclone-api/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/rclone-api/actions/workflows/lint.yml)
32
+ [![MacOS_Tests](https://github.com/zackees/rclone-api/actions/workflows/push_macos.yml/badge.svg)](https://github.com/zackees/rclone-api/actions/workflows/push_macos.yml)
33
+ [![Ubuntu_Tests](https://github.com/zackees/rclone-api/actions/workflows/push_ubuntu.yml/badge.svg)](https://github.com/zackees/rclone-api/actions/workflows/push_ubuntu.yml)
34
+ [![Win_Tests](https://github.com/zackees/rclone-api/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/rclone-api/actions/workflows/push_win.yml)
35
+ -->
36
+
37
+
38
+ Got a lot of data to transfer quickly? This package is for you.
39
+
40
+ This library was built out of necessity to transfer large amounts of AI training data. Aggressive defaults means this api will transfer faster than rclone does in stock settings.
41
+
42
+ You can have [rclone](https://rclone.org/) in your path or else the api will download it.
43
+
44
+ # Install
45
+
46
+ `pip install rclone-api`
47
+
48
+ pypi link: https://pypi.org/project/rclone-api/
49
+
50
+ # Quick
51
+
52
+ In addition to providing easy python use for rclone, this package provides additional features:
53
+
54
+ * Aggressive default settings for copying / syncing operations for extreme performance.
55
+ * Database Support: Dump repo information to an sqlite/postgres/mysql database.
56
+ * One repo path -> table.
57
+ * Scoped objects for:
58
+ * Mounts.
59
+ * File servers.
60
+ * Enforces correct cleanup
61
+ * Mounts are easier - platform specific setup and teardown.
62
+ * Resumable multi-part uploads when s3 is the destination.
63
+ * Fast diffing src/dst repos as a stream of `list[str]`.
64
+ * Find which files need are missing and need to be copied.
65
+ * Efficiently build pipelines to select copy strategy based on file size.
66
+ * Walk a directory.
67
+ * Breath first.
68
+ * Depth first.
69
+ * Use the HttpServer to slice out byte ranges from extremely large files.
70
+
71
+
72
+ ## Example
73
+
74
+ ```python
75
+
76
+ from rclone_api import Rclone, DirListing, Config
77
+
78
+ RCLONE_CONFIG = Config("""
79
+ [dst]
80
+ type = s3
81
+ account = *********
82
+ key = ************
83
+ """)
84
+
85
+
86
+ def test_ls_glob_png(self) -> None:
87
+ rclone = Rclone(RCLONE_CONFIG)
88
+ path = f"dst:{BUCKET_NAME}/my_data"
89
+ listing: DirListing = rclone.ls(path, glob="*.png")
90
+ self.assertGreater(len(listing.files), 0)
91
+ for file in listing.files:
92
+ self.assertIsInstance(file, File)
93
+ # test that it ends with .png
94
+ self.assertTrue(file.name.endswith(".png"))
95
+ # there should be no directories with this glob
96
+ self.assertEqual(len(listing.dirs), 0)
97
+ ```
98
+
99
+ ## API
100
+
101
+ ```python
102
+ class Rclone:
103
+ """
104
+ Main interface for interacting with Rclone.
105
+
106
+ This class provides methods for all major Rclone operations including
107
+ file transfers, listing, mounting, and remote management.
108
+
109
+ It serves as the primary entry point for the API, wrapping the underlying
110
+ implementation details and providing a clean, consistent interface.
111
+ """
112
+ def __init__(
113
+ self, rclone_conf: Path | Config, rclone_exe: Path | None = None
114
+ ) -> None:
115
+ """
116
+ Initialize the Rclone interface.
117
+
118
+ Args:
119
+ rclone_conf: Path to rclone config file or Config object
120
+ rclone_exe: Optional path to rclone executable. If None, will search in PATH.
121
+ """
122
+ from rclone_api.rclone_impl import RcloneImpl
123
+
124
+ self.impl: RcloneImpl = RcloneImpl(rclone_conf, rclone_exe)
125
+
126
+ def webgui(self, other_args: list[str] | None = None) -> Process:
127
+ """
128
+ Launch the Rclone web GUI.
129
+
130
+ Starts the built-in web interface for interacting with rclone.
131
+
132
+ Args:
133
+ other_args: Additional command-line arguments to pass to rclone
134
+
135
+ Returns:
136
+ Process object representing the running web GUI
137
+ """
138
+ return self.impl.webgui(other_args=other_args)
139
+
140
+ def launch_server(
141
+ self,
142
+ addr: str,
143
+ user: str | None = None,
144
+ password: str | None = None,
145
+ other_args: list[str] | None = None,
146
+ ) -> Process:
147
+ """
148
+ Launch the Rclone server so it can receive commands.
149
+
150
+ Starts an rclone server that can be controlled remotely.
151
+
152
+ Args:
153
+ addr: Address and port to listen on (e.g., "localhost:5572")
154
+ user: Optional username for authentication
155
+ password: Optional password for authentication
156
+ other_args: Additional command-line arguments
157
+
158
+ Returns:
159
+ Process object representing the running server
160
+ """
161
+ return self.impl.launch_server(
162
+ addr=addr, user=user, password=password, other_args=other_args
163
+ )
164
+
165
+ def remote_control(
166
+ self,
167
+ addr: str,
168
+ user: str | None = None,
169
+ password: str | None = None,
170
+ capture: bool | None = None,
171
+ other_args: list[str] | None = None,
172
+ ) -> CompletedProcess:
173
+ """
174
+ Send commands to a running rclone server.
175
+
176
+ Args:
177
+ addr: Address of the rclone server (e.g., "localhost:5572")
178
+ user: Optional username for authentication
179
+ password: Optional password for authentication
180
+ capture: Whether to capture and return command output
181
+ other_args: Additional command-line arguments
182
+
183
+ Returns:
184
+ CompletedProcess containing the command result
185
+ """
186
+ return self.impl.remote_control(
187
+ addr=addr,
188
+ user=user,
189
+ password=password,
190
+ capture=capture,
191
+ other_args=other_args,
192
+ )
193
+
194
+ def obscure(self, password: str) -> str:
195
+ """
196
+ Obscure a password for use in rclone config files.
197
+
198
+ Converts a plaintext password to rclone's obscured format.
199
+ Note that this is not secure encryption, just light obfuscation.
200
+
201
+ Args:
202
+ password: The plaintext password to obscure
203
+
204
+ Returns:
205
+ The obscured password string
206
+ """
207
+ return self.impl.obscure(password=password)
208
+
209
+ def ls_stream(
210
+ self,
211
+ path: str,
212
+ max_depth: int = -1,
213
+ fast_list: bool = False,
214
+ ) -> FilesStream:
215
+ """
216
+ List files in the given path as a stream of results.
217
+
218
+ This method is memory-efficient for large directories as it yields
219
+ results incrementally rather than collecting them all at once.
220
+
221
+ Args:
222
+ path: Remote path to list
223
+ max_depth: Maximum recursion depth (-1 for unlimited)
224
+ fast_list: Use fast list (only recommended for listing entire repositories or small datasets)
225
+
226
+ Returns:
227
+ A stream of file entries that can be iterated over
228
+ """
229
+ return self.impl.ls_stream(path=path, max_depth=max_depth, fast_list=fast_list)
230
+
231
+ def save_to_db(
232
+ self,
233
+ src: str,
234
+ db_url: str, # sqalchemy style url, use sqlite:///data.db or mysql://user:pass@localhost/db or postgres://user:pass@localhost/db
235
+ max_depth: int = -1,
236
+ fast_list: bool = False,
237
+ ) -> None:
238
+ """
239
+ Save files to a database (sqlite, mysql, postgres).
240
+
241
+ Lists all files in the source path and stores their metadata in a database.
242
+ Useful for creating searchable indexes of remote storage.
243
+
244
+ Args:
245
+ src: Remote path to list, this will be used to populate an entire table, so always use the root-most path.
246
+ db_url: Database URL, like sqlite:///data.db or mysql://user:pass@localhost/db or postgres://user:pass@localhost/db
247
+ max_depth: Maximum depth to traverse (-1 for unlimited)
248
+ fast_list: Use fast list (only use when getting THE entire data repository from the root/bucket)
249
+ """
250
+ return self.impl.save_to_db(
251
+ src=src, db_url=db_url, max_depth=max_depth, fast_list=fast_list
252
+ )
253
+
254
+ def ls(
255
+ self,
256
+ path: Dir | Remote | str | None = None,
257
+ max_depth: int | None = None,
258
+ glob: str | None = None,
259
+ order: Order = Order.NORMAL,
260
+ listing_option: ListingOption = ListingOption.ALL,
261
+ ) -> DirListing:
262
+ """
263
+ List files and directories at the specified path.
264
+
265
+ Provides a detailed listing with file metadata.
266
+
267
+ Args:
268
+ path: Path to list (Dir, Remote, or string path)
269
+ max_depth: Maximum recursion depth (None for default)
270
+ glob: Optional glob pattern to filter results
271
+ order: Sorting order for the results
272
+ listing_option: What types of entries to include
273
+
274
+ Returns:
275
+ DirListing object containing the results
276
+ """
277
+ return self.impl.ls(
278
+ path=path,
279
+ max_depth=max_depth,
280
+ glob=glob,
281
+ order=order,
282
+ listing_option=listing_option,
283
+ )
284
+
285
+ def listremotes(self) -> list[Remote]:
286
+ """
287
+ List all configured remotes.
288
+
289
+ Returns a list of all remotes defined in the rclone configuration.
290
+
291
+ Returns:
292
+ List of Remote objects
293
+ """
294
+ return self.impl.listremotes()
295
+
296
+ def diff(
297
+ self,
298
+ src: str,
299
+ dst: str,
300
+ min_size: (
301
+ str | None
302
+ ) = None, # e. g. "1MB" - see rclone documentation: https://rclone.org/commands/rclone_check/
303
+ max_size: (
304
+ str | None
305
+ ) = None, # e. g. "1GB" - see rclone documentation: https://rclone.org/commands/rclone_check/
306
+ diff_option: DiffOption = DiffOption.COMBINED,
307
+ fast_list: bool = True,
308
+ size_only: bool | None = None,
309
+ checkers: int | None = None,
310
+ other_args: list[str] | None = None,
311
+ ) -> Generator[DiffItem, None, None]:
312
+ """
313
+ Compare two directories and yield differences.
314
+
315
+ Be extra careful with the src and dst values. If you are off by one
316
+ parent directory, you will get a huge amount of false diffs.
317
+
318
+ Args:
319
+ src: Rclone style src path
320
+ dst: Rclone style dst path
321
+ min_size: Minimum file size to check (e.g., "1MB")
322
+ max_size: Maximum file size to check (e.g., "1GB")
323
+ diff_option: How to report differences
324
+ fast_list: Whether to use fast listing
325
+ size_only: Compare only file sizes, not content
326
+ checkers: Number of checker threads
327
+ other_args: Additional command-line arguments
328
+
329
+ Yields:
330
+ DiffItem objects representing each difference found
331
+ """
332
+ return self.impl.diff(
333
+ src=src,
334
+ dst=dst,
335
+ min_size=min_size,
336
+ max_size=max_size,
337
+ diff_option=diff_option,
338
+ fast_list=fast_list,
339
+ size_only=size_only,
340
+ checkers=checkers,
341
+ other_args=other_args,
342
+ )
343
+
344
+ def walk(
345
+ self,
346
+ path: Dir | Remote | str,
347
+ max_depth: int = -1,
348
+ breadth_first: bool = True,
349
+ order: Order = Order.NORMAL,
350
+ ) -> Generator[DirListing, None, None]:
351
+ """
352
+ Walk through the given path recursively, yielding directory listings.
353
+
354
+ Similar to os.walk(), but for remote storage. Traverses directories
355
+ and yields their contents.
356
+
357
+ Args:
358
+ path: Remote path, Dir, or Remote object to walk through
359
+ max_depth: Maximum depth to traverse (-1 for unlimited)
360
+ breadth_first: If True, use breadth-first traversal, otherwise depth-first
361
+ order: Sorting order for directory entries
362
+
363
+ Yields:
364
+ DirListing: Directory listing for each directory encountered
365
+ """
366
+ return self.impl.walk(
367
+ path=path, max_depth=max_depth, breadth_first=breadth_first, order=order
368
+ )
369
+
370
+ def scan_missing_folders(
371
+ self,
372
+ src: Dir | Remote | str,
373
+ dst: Dir | Remote | str,
374
+ max_depth: int = -1,
375
+ order: Order = Order.NORMAL,
376
+ ) -> Generator[Dir, None, None]:
377
+ """
378
+ Find folders that exist in source but are missing in destination.
379
+
380
+ Useful for identifying directories that need to be created before
381
+ copying files.
382
+
383
+ Args:
384
+ src: Source directory or Remote to scan
385
+ dst: Destination directory or Remote to compare against
386
+ max_depth: Maximum depth to traverse (-1 for unlimited)
387
+ order: Sorting order for directory entries
388
+
389
+ Yields:
390
+ Dir: Each directory that exists in source but not in destination
391
+ """
392
+ return self.impl.scan_missing_folders(
393
+ src=src, dst=dst, max_depth=max_depth, order=order
394
+ )
395
+
396
+ def cleanup(
397
+ self, path: str, other_args: list[str] | None = None
398
+ ) -> CompletedProcess:
399
+ """
400
+ Cleanup any resources used by the Rclone instance.
401
+
402
+ Removes temporary files and directories created by rclone.
403
+
404
+ Args:
405
+ path: Path to clean up
406
+ other_args: Additional command-line arguments
407
+
408
+ Returns:
409
+ CompletedProcess with the result of the cleanup operation
410
+ """
411
+ return self.impl.cleanup(path=path, other_args=other_args)
412
+
413
+ def copy_to(
414
+ self,
415
+ src: File | str,
416
+ dst: File | str,
417
+ check: bool | None = None,
418
+ verbose: bool | None = None,
419
+ other_args: list[str] | None = None,
420
+ ) -> CompletedProcess:
421
+ """
422
+ Copy one file from source to destination.
423
+
424
+ Warning - this can be slow for large files or when copying between
425
+ different storage providers.
426
+
427
+ Args:
428
+ src: Rclone style src path
429
+ dst: Rclone style dst path
430
+ check: Whether to verify the copy with checksums
431
+ verbose: Whether to show detailed progress
432
+ other_args: Additional command-line arguments
433
+
434
+ Returns:
435
+ CompletedProcess with the result of the copy operation
436
+ """
437
+ return self.impl.copy_to(
438
+ src=src, dst=dst, check=check, verbose=verbose, other_args=other_args
439
+ )
440
+
441
+ def copy_files(
442
+ self,
443
+ src: str,
444
+ dst: str,
445
+ files: list[str] | Path,
446
+ check: bool | None = None,
447
+ max_backlog: int | None = None,
448
+ verbose: bool | None = None,
449
+ checkers: int | None = None,
450
+ transfers: int | None = None,
451
+ low_level_retries: int | None = None,
452
+ retries: int | None = None,
453
+ retries_sleep: str | None = None,
454
+ metadata: bool | None = None,
455
+ timeout: str | None = None,
456
+ max_partition_workers: int | None = None,
457
+ multi_thread_streams: int | None = None,
458
+ other_args: list[str] | None = None,
459
+ ) -> list[CompletedProcess]:
460
+ """
461
+ Copy multiple files from source to destination.
462
+
463
+ Efficiently copies a list of files, potentially in parallel.
464
+
465
+ Args:
466
+ src: Rclone style src path
467
+ dst: Rclone style dst path
468
+ files: List of file paths relative to src, or Path to a file containing the list
469
+ check: Whether to verify copies with checksums
470
+ max_backlog: Maximum number of queued transfers
471
+ verbose: Whether to show detailed progress
472
+ checkers: Number of checker threads
473
+ transfers: Number of file transfers to run in parallel
474
+ low_level_retries: Number of low-level retries
475
+ retries: Number of high-level retries
476
+ retries_sleep: Sleep interval between retries (e.g., "10s")
477
+ metadata: Whether to preserve metadata
478
+ timeout: IO idle timeout (e.g., "5m")
479
+ max_partition_workers: Maximum number of partition workers
480
+ multi_thread_streams: Number of streams for multi-thread copy
481
+ other_args: Additional command-line arguments
482
+
483
+ Returns:
484
+ List of CompletedProcess objects for each copy operation
485
+ """
486
+ return self.impl.copy_files(
487
+ src=src,
488
+ dst=dst,
489
+ files=files,
490
+ check=check,
491
+ max_backlog=max_backlog,
492
+ verbose=verbose,
493
+ checkers=checkers,
494
+ transfers=transfers,
495
+ low_level_retries=low_level_retries,
496
+ retries=retries,
497
+ retries_sleep=retries_sleep,
498
+ metadata=metadata,
499
+ timeout=timeout,
500
+ max_partition_workers=max_partition_workers,
501
+ multi_thread_streams=multi_thread_streams,
502
+ other_args=other_args,
503
+ )
504
+
505
+ def copy(
506
+ self,
507
+ src: Dir | str,
508
+ dst: Dir | str,
509
+ check: bool | None = None,
510
+ transfers: int | None = None,
511
+ checkers: int | None = None,
512
+ multi_thread_streams: int | None = None,
513
+ low_level_retries: int | None = None,
514
+ retries: int | None = None,
515
+ other_args: list[str] | None = None,
516
+ ) -> CompletedProcess:
517
+ """
518
+ Copy files from source to destination.
519
+
520
+ Recursively copies all files from src to dst.
521
+
522
+ Args:
523
+ src: Rclone style src path
524
+ dst: Rclone style dst path
525
+ check: Whether to verify copies with checksums
526
+ transfers: Number of file transfers to run in parallel
527
+ checkers: Number of checker threads
528
+ multi_thread_streams: Number of streams for multi-thread copy
529
+ low_level_retries: Number of low-level retries
530
+ retries: Number of high-level retries
531
+ other_args: Additional command-line arguments
532
+
533
+ Returns:
534
+ CompletedProcess with the result of the copy operation
535
+ """
536
+ return self.impl.copy(
537
+ src=src,
538
+ dst=dst,
539
+ check=check,
540
+ transfers=transfers,
541
+ checkers=checkers,
542
+ multi_thread_streams=multi_thread_streams,
543
+ low_level_retries=low_level_retries,
544
+ retries=retries,
545
+ other_args=other_args,
546
+ )
547
+
548
+ def purge(self, path: Dir | str) -> CompletedProcess:
549
+ """
550
+ Purge a directory.
551
+
552
+ Removes a directory and all its contents.
553
+
554
+ Args:
555
+ path: Rclone style path
556
+
557
+ Returns:
558
+ CompletedProcess with the result of the purge operation
559
+ """
560
+ return self.impl.purge(path=path)
561
+
562
+ def delete_files(
563
+ self,
564
+ files: str | File | list[str] | list[File],
565
+ check: bool | None = None,
566
+ rmdirs=False,
567
+ verbose: bool | None = None,
568
+ max_partition_workers: int | None = None,
569
+ other_args: list[str] | None = None,
570
+ ) -> CompletedProcess:
571
+ """
572
+ Delete files or directories.
573
+
574
+ Args:
575
+ files: Files to delete (single file/path or list)
576
+ check: Whether to verify deletions
577
+ rmdirs: Whether to remove empty directories
578
+ verbose: Whether to show detailed progress
579
+ max_partition_workers: Maximum number of partition workers
580
+ other_args: Additional command-line arguments
581
+
582
+ Returns:
583
+ CompletedProcess with the result of the delete operation
584
+ """
585
+ return self.impl.delete_files(
586
+ files=files,
587
+ check=check,
588
+ rmdirs=rmdirs,
589
+ verbose=verbose,
590
+ max_partition_workers=max_partition_workers,
591
+ other_args=other_args,
592
+ )
593
+
594
+ def exists(self, path: Dir | Remote | str | File) -> bool:
595
+ """
596
+ Check if a file or directory exists.
597
+
598
+ Args:
599
+ path: Path to check (Dir, Remote, File, or path string)
600
+
601
+ Returns:
602
+ True if the path exists, False otherwise
603
+ """
604
+ return self.impl.exists(path=path)
605
+
606
+ def is_synced(self, src: str | Dir, dst: str | Dir) -> bool:
607
+ """
608
+ Check if two directories are in sync.
609
+
610
+ Compares the contents of src and dst to determine if they match.
611
+
612
+ Args:
613
+ src: Source directory (Dir object or path string)
614
+ dst: Destination directory (Dir object or path string)
615
+
616
+ Returns:
617
+ True if the directories are in sync, False otherwise
618
+ """
619
+ return self.impl.is_synced(src=src, dst=dst)
620
+
621
+ def modtime(self, src: str) -> str | Exception:
622
+ """
623
+ Get the modification time of a file or directory.
624
+
625
+ Args:
626
+ src: Path to the file or directory
627
+
628
+ Returns:
629
+ Modification time as a string, or Exception if an error occurred
630
+ """
631
+ return self.impl.modtime(src=src)
632
+
633
+ def modtime_dt(self, src: str) -> datetime | Exception:
634
+ """
635
+ Get the modification time of a file or directory as a datetime object.
636
+
637
+ Args:
638
+ src: Path to the file or directory
639
+
640
+ Returns:
641
+ Modification time as a datetime object, or Exception if an error occurred
642
+ """
643
+ return self.impl.modtime_dt(src=src)
644
+
645
+ def write_text(
646
+ self,
647
+ text: str,
648
+ dst: str,
649
+ ) -> Exception | None:
650
+ """
651
+ Write text to a file.
652
+
653
+ Creates or overwrites the file at dst with the given text.
654
+
655
+ Args:
656
+ text: Text content to write
657
+ dst: Destination file path
658
+
659
+ Returns:
660
+ None if successful, Exception if an error occurred
661
+ """
662
+ return self.impl.write_text(text=text, dst=dst)
663
+
664
+ def write_bytes(
665
+ self,
666
+ data: bytes,
667
+ dst: str,
668
+ ) -> Exception | None:
669
+ """
670
+ Write bytes to a file.
671
+
672
+ Creates or overwrites the file at dst with the given binary data.
673
+
674
+ Args:
675
+ data: Binary content to write
676
+ dst: Destination file path
677
+
678
+ Returns:
679
+ None if successful, Exception if an error occurred
680
+ """
681
+ return self.impl.write_bytes(data=data, dst=dst)
682
+
683
+ def read_bytes(self, src: str) -> bytes | Exception:
684
+ """
685
+ Read bytes from a file.
686
+
687
+ Args:
688
+ src: Source file path
689
+
690
+ Returns:
691
+ File contents as bytes, or Exception if an error occurred
692
+ """
693
+ return self.impl.read_bytes(src=src)
694
+
695
+ def read_text(self, src: str) -> str | Exception:
696
+ """
697
+ Read text from a file.
698
+
699
+ Args:
700
+ src: Source file path
701
+
702
+ Returns:
703
+ File contents as a string, or Exception if an error occurred
704
+ """
705
+ return self.impl.read_text(src=src)
706
+
707
+ def copy_bytes(
708
+ self,
709
+ src: str,
710
+ offset: int | SizeSuffix,
711
+ length: int | SizeSuffix,
712
+ outfile: Path,
713
+ other_args: list[str] | None = None,
714
+ ) -> Exception | None:
715
+ """
716
+ Copy a slice of bytes from the src file to dst.
717
+
718
+ Extracts a portion of a file based on offset and length.
719
+
720
+ Args:
721
+ src: Source file path
722
+ offset: Starting position in the source file
723
+ length: Number of bytes to copy
724
+ outfile: Local file path to write the bytes to
725
+ other_args: Additional command-line arguments
726
+
727
+ Returns:
728
+ None if successful, Exception if an error occurred
729
+ """
730
+ return self.impl.copy_bytes(
731
+ src=src,
732
+ offset=offset,
733
+ length=length,
734
+ outfile=outfile,
735
+ other_args=other_args,
736
+ )
737
+
738
+ def copy_dir(
739
+ self, src: str | Dir, dst: str | Dir, args: list[str] | None = None
740
+ ) -> CompletedProcess:
741
+ """
742
+ Copy a directory from source to destination.
743
+
744
+ Recursively copies all files and subdirectories.
745
+
746
+ Args:
747
+ src: Source directory (Dir object or path string)
748
+ dst: Destination directory (Dir object or path string)
749
+ args: Additional command-line arguments
750
+
751
+ Returns:
752
+ CompletedProcess with the result of the copy operation
753
+ """
754
+ # convert src to str, also dst
755
+ return self.impl.copy_dir(src=src, dst=dst, args=args)
756
+
757
+ def copy_remote(
758
+ self, src: Remote, dst: Remote, args: list[str] | None = None
759
+ ) -> CompletedProcess:
760
+ """
761
+ Copy a remote to another remote.
762
+
763
+ Copies all contents from one remote storage to another.
764
+
765
+ Args:
766
+ src: Source remote
767
+ dst: Destination remote
768
+ args: Additional command-line arguments
769
+
770
+ Returns:
771
+ CompletedProcess with the result of the copy operation
772
+ """
773
+ return self.impl.copy_remote(src=src, dst=dst, args=args)
774
+
775
+ def copy_file_s3_resumable(
776
+ self,
777
+ src: str, # src:/Bucket/path/myfile.large.zst
778
+ dst: str, # dst:/Bucket/path/myfile.large.zst
779
+ part_infos: list[PartInfo] | None = None,
780
+ upload_threads: int = 8, # Number of reader and writer threads to use
781
+ merge_threads: int = 4, # Number of threads to use for merging the parts
782
+ ) -> Exception | None:
783
+ """
784
+ Copy a large file to S3 with resumable upload capability.
785
+
786
+ This method splits the file into parts for parallel upload and can
787
+ resume interrupted transfers using a custom algorithm in python.
788
+
789
+ Particularly useful for very large files where network interruptions
790
+ are likely.
791
+
792
+ Args:
793
+ src: Source file path (format: remote:bucket/path/file)
794
+ dst: Destination file path (format: remote:bucket/path/file)
795
+ part_infos: Optional list of part information for resuming uploads
796
+ upload_threads: Number of parallel upload threads
797
+ merge_threads: Number of threads for merging uploaded parts
798
+
799
+ Returns:
800
+ None if successful, Exception if an error occurred
801
+ """
802
+ return self.impl.copy_file_s3_resumable(
803
+ src=src,
804
+ dst=dst,
805
+ part_infos=part_infos,
806
+ upload_threads=upload_threads,
807
+ merge_threads=merge_threads,
808
+ )
809
+
810
+ def mount(
811
+ self,
812
+ src: Remote | Dir | str,
813
+ outdir: Path,
814
+ allow_writes: bool | None = False,
815
+ use_links: bool | None = None,
816
+ vfs_cache_mode: str | None = None,
817
+ verbose: bool | None = None,
818
+ cache_dir: Path | None = None,
819
+ cache_dir_delete_on_exit: bool | None = None,
820
+ log: Path | None = None,
821
+ other_args: list[str] | None = None,
822
+ ) -> Mount:
823
+ """
824
+ Mount a remote or directory to a local path.
825
+
826
+ Makes remote storage accessible as a local filesystem.
827
+
828
+ Args:
829
+ src: Remote or directory to mount
830
+ outdir: Local path to mount to
831
+ allow_writes: Whether to allow write operations
832
+ use_links: Whether to use symbolic links
833
+ vfs_cache_mode: VFS cache mode (e.g., "full", "minimal")
834
+ verbose: Whether to show detailed output
835
+ cache_dir: Directory to use for caching
836
+ cache_dir_delete_on_exit: Whether to delete cache on exit
837
+ log: Path to write logs to
838
+ other_args: Additional command-line arguments
839
+
840
+ Returns:
841
+ Mount object representing the mounted filesystem
842
+ """
843
+ return self.impl.mount(
844
+ src=src,
845
+ outdir=outdir,
846
+ allow_writes=allow_writes,
847
+ use_links=use_links,
848
+ vfs_cache_mode=vfs_cache_mode,
849
+ verbose=verbose,
850
+ cache_dir=cache_dir,
851
+ cache_dir_delete_on_exit=cache_dir_delete_on_exit,
852
+ log=log,
853
+ other_args=other_args,
854
+ )
855
+
856
+ def serve_http(
857
+ self,
858
+ src: str,
859
+ addr: str = "localhost:8080",
860
+ other_args: list[str] | None = None,
861
+ ) -> HttpServer:
862
+ """
863
+ Serve a remote or directory via HTTP.
864
+
865
+ Creates an HTTP server that provides access to the specified remote.
866
+ The returned HttpServer object includes a client for fetching files.
867
+
868
+ This is useful for providing web access to remote storage or for
869
+ accessing remote files from applications that support HTTP but not
870
+ the remote's native protocol.
871
+
872
+ Args:
873
+ src: Remote or directory to serve
874
+ addr: Network address and port to serve on (default: localhost:8080)
875
+ other_args: Additional arguments to pass to rclone
876
+
877
+ Returns:
878
+ HttpServer object with methods for accessing the served content
879
+ """
880
+ return self.impl.serve_http(src=src, addr=addr, other_args=other_args)
881
+
882
+ def size_files(
883
+ self,
884
+ src: str,
885
+ files: list[str],
886
+ fast_list: bool = False, # Recommend that this is False
887
+ other_args: list[str] | None = None,
888
+ check: bool | None = False,
889
+ verbose: bool | None = None,
890
+ ) -> SizeResult | Exception:
891
+ """
892
+ Get the size of a list of files.
893
+
894
+ Calculates the total size of the specified files.
895
+
896
+ Args:
897
+ src: Base path for the files
898
+ files: List of file paths relative to src
899
+ fast_list: Whether to use fast listing (not recommended for accuracy)
900
+ other_args: Additional command-line arguments
901
+ check: Whether to verify file integrity
902
+ verbose: Whether to show detailed output
903
+
904
+ Returns:
905
+ SizeResult with size information, or Exception if an error occurred
906
+
907
+ Example:
908
+ size_files("remote:bucket", ["path/to/file1", "path/to/file2"])
909
+ """
910
+ return self.impl.size_files(
911
+ src=src,
912
+ files=files,
913
+ fast_list=fast_list,
914
+ other_args=other_args,
915
+ check=check,
916
+ verbose=verbose,
917
+ )
918
+
919
+ def size_file(self, src: str) -> SizeSuffix | Exception:
920
+ """
921
+ Get the size of a file.
922
+
923
+ Args:
924
+ src: Path to the file
925
+
926
+ Returns:
927
+ SizeSuffix object representing the file size, or Exception if an error occurred
928
+ """
929
+ return self.impl.size_file(src=src)
930
+ ```
931
+
932
+
933
+ # Contributing
934
+
935
+ ```bash
936
+ git clone https://github.comn/zackees/rclone-api
937
+ cd rclone-api
938
+ ./install
939
+ ./lint
940
+ ./test
941
+ ```
942
+
943
+ # Windows
944
+
945
+ This environment requires you to use `git-bash`.