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