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