cloudpathlib.local¶
This module implements "Local" classes that mimic their associated cloudpathlib non-local
counterparts but use the local filesystem in place of cloud storage. They can be used as drop-in
replacements, with the intent that you can use them as mock or monkepatch substitutes in your
tests. See "Testing code that uses cloudpathlib" for usage
examples.
Attributes¶
local_azure_blob_implementation = CloudImplementation()
module-attribute
¶
Replacement for "azure" CloudImplementation meta object in cloudpathlib.implementation_registry
local_gs_implementation = CloudImplementation()
module-attribute
¶
Replacement for "gs" CloudImplementation meta object in cloudpathlib.implementation_registry
local_s3_implementation = CloudImplementation()
module-attribute
¶
Replacement for "s3" CloudImplementation meta object in cloudpathlib.implementation_registry
Classes¶
LocalAzureBlobClient
¶
Bases: LocalClient
Replacement for AzureBlobClient that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/azure.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args, **kwargs)
¶
Source code in cloudpathlib/local/implementations/azure.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
LocalAzureBlobPath
¶
Bases: LocalPath
Replacement for AzureBlobPath that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/azure.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
Attributes¶
anchor: str
property
¶
blob: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str = 'az://'
class-attribute
instance-attribute
¶
container: str
property
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
md5: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/implementations/azure.py
55 56 57 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
LocalClient
¶
Bases: Client
Abstract client for accessing objects the local filesystem. Subclasses are as a monkeypatch substitutes for normal Client subclasses when writing tests.
Source code in cloudpathlib/local/localclient.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args: Any, local_storage_dir: Optional[Union[str, os.PathLike]] = None, file_cache_mode: Optional[Union[str, FileCacheMode]] = None, local_cache_dir: Optional[Union[str, os.PathLike]] = None, content_type_method: Optional[Callable] = mimetypes.guess_type, **kwargs: Any) -> None
¶
Source code in cloudpathlib/local/localclient.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
LocalGSClient
¶
Bases: LocalClient
Replacement for GSClient that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/gs.py
14 15 16 17 18 19 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args: Any, local_storage_dir: Optional[Union[str, os.PathLike]] = None, file_cache_mode: Optional[Union[str, FileCacheMode]] = None, local_cache_dir: Optional[Union[str, os.PathLike]] = None, content_type_method: Optional[Callable] = mimetypes.guess_type, **kwargs: Any) -> None
¶
Source code in cloudpathlib/local/localclient.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
LocalGSPath
¶
Bases: LocalPath
Replacement for GSPath that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/gs.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
Attributes¶
anchor: str
property
¶
blob: str
property
¶
bucket: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str = 'gs://'
class-attribute
instance-attribute
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
md5: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/implementations/gs.py
37 38 39 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
LocalPath
¶
Bases: CloudPath
Abstract CloudPath for accessing objects the local filesystem. Subclasses are as a monkeypatch substitutes for normal CloudPath subclasses when writing tests.
Source code in cloudpathlib/local/localpath.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
Attributes¶
anchor: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str
instance-attribute
¶
drive: str
abstractmethod
property
¶
For example "bucket" on S3 or "container" on Azure; needs to be defined for each class
fspath: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents: bool = False, exist_ok: bool = False, mode: Optional[Any] = None) -> None
abstractmethod
¶
Should be implemented using the client API without requiring a dir is downloaded
Source code in cloudpathlib/cloudpath.py
448 449 450 451 452 453 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
LocalS3Client
¶
Bases: LocalClient
Replacement for S3Client that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/s3.py
14 15 16 17 18 19 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args: Any, local_storage_dir: Optional[Union[str, os.PathLike]] = None, file_cache_mode: Optional[Union[str, FileCacheMode]] = None, local_cache_dir: Optional[Union[str, os.PathLike]] = None, content_type_method: Optional[Callable] = mimetypes.guess_type, **kwargs: Any) -> None
¶
Source code in cloudpathlib/local/localclient.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
LocalS3Path
¶
Bases: LocalPath
Replacement for S3Path that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/s3.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
Attributes¶
anchor: str
property
¶
bucket: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str = 's3://'
class-attribute
instance-attribute
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
key: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/implementations/s3.py
37 38 39 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
Attributes¶
Classes¶
Bases: LocalClient
Replacement for AzureBlobClient that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/azure.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args, **kwargs)
¶
Source code in cloudpathlib/local/implementations/azure.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
Bases: LocalPath
Replacement for AzureBlobPath that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/azure.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
Attributes¶
anchor: str
property
¶
blob: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str = 'az://'
class-attribute
instance-attribute
¶
container: str
property
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
md5: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/implementations/azure.py
55 56 57 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
Bases: Client
Abstract client for accessing objects the local filesystem. Subclasses are as a monkeypatch substitutes for normal Client subclasses when writing tests.
Source code in cloudpathlib/local/localclient.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args: Any, local_storage_dir: Optional[Union[str, os.PathLike]] = None, file_cache_mode: Optional[Union[str, FileCacheMode]] = None, local_cache_dir: Optional[Union[str, os.PathLike]] = None, content_type_method: Optional[Callable] = mimetypes.guess_type, **kwargs: Any) -> None
¶
Source code in cloudpathlib/local/localclient.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
Bases: LocalClient
Replacement for GSClient that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/gs.py
14 15 16 17 18 19 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args: Any, local_storage_dir: Optional[Union[str, os.PathLike]] = None, file_cache_mode: Optional[Union[str, FileCacheMode]] = None, local_cache_dir: Optional[Union[str, os.PathLike]] = None, content_type_method: Optional[Callable] = mimetypes.guess_type, **kwargs: Any) -> None
¶
Source code in cloudpathlib/local/localclient.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
Bases: LocalPath
Replacement for GSPath that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/gs.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
Attributes¶
anchor: str
property
¶
blob: str
property
¶
bucket: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str = 'gs://'
class-attribute
instance-attribute
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
md5: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/implementations/gs.py
37 38 39 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
Bases: CloudPath
Abstract CloudPath for accessing objects the local filesystem. Subclasses are as a monkeypatch substitutes for normal CloudPath subclasses when writing tests.
Source code in cloudpathlib/local/localpath.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
Attributes¶
anchor: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str
instance-attribute
¶
drive: str
abstractmethod
property
¶
For example "bucket" on S3 or "container" on Azure; needs to be defined for each class
fspath: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents: bool = False, exist_ok: bool = False, mode: Optional[Any] = None) -> None
abstractmethod
¶
Should be implemented using the client API without requiring a dir is downloaded
Source code in cloudpathlib/cloudpath.py
448 449 450 451 452 453 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
Bases: LocalClient
Replacement for S3Client that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/s3.py
14 15 16 17 18 19 | |
Attributes¶
content_type_method = content_type_method
instance-attribute
¶
file_cache_mode = file_cache_mode
instance-attribute
¶
local_storage_dir: Path
property
¶
The local directory where files are stored for this client. This storage directory is the one that simulates the cloud. If no storage directory was provided on instantiating the client, the default storage directory for this client class is used.
Methods:¶
CloudPath(cloud_path: Union[str, BoundedCloudPath], *parts: str) -> BoundedCloudPath
¶
Source code in cloudpathlib/client.py
133 134 | |
__init__(*args: Any, local_storage_dir: Optional[Union[str, os.PathLike]] = None, file_cache_mode: Optional[Union[str, FileCacheMode]] = None, local_cache_dir: Optional[Union[str, os.PathLike]] = None, content_type_method: Optional[Callable] = mimetypes.guess_type, **kwargs: Any) -> None
¶
Source code in cloudpathlib/local/localclient.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
clear_cache()
¶
Clears the contents of the cache folder. Does not remove folder so it can keep being written to.
Source code in cloudpathlib/client.py
136 137 138 139 140 141 142 143 144 145 | |
get_default_client() -> Client[BoundedCloudPath]
classmethod
¶
Get the default client, which the one that is used when instantiating a cloud path instance for this cloud without a client specified.
Source code in cloudpathlib/client.py
119 120 121 122 123 124 125 126 | |
get_default_storage_dir() -> Path
classmethod
¶
Return the default storage directory for this client class. This is used if a client is instantiated without a storage directory being explicitly provided. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
60 61 62 63 64 65 66 67 68 69 | |
reset_default_storage_dir() -> Path
classmethod
¶
Reset the default storage directly. This tears down and recreates the directory used by default for this client class when instantiating a client without explicitly providing a storage directory. In this usage, "storage" refers to the local storage that simulates the cloud.
Source code in cloudpathlib/local/localclient.py
71 72 73 74 75 76 77 78 79 | |
set_as_default_client() -> None
¶
Set this client instance as the default one used when instantiating cloud path instances for this cloud without a client specified.
Source code in cloudpathlib/client.py
128 129 130 131 | |
Bases: LocalPath
Replacement for S3Path that uses the local file system. Intended as a monkeypatch substitute when writing tests.
Source code in cloudpathlib/local/implementations/s3.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
Attributes¶
anchor: str
property
¶
bucket: str
property
¶
client: LocalClient
instance-attribute
¶
cloud_prefix: str = 's3://'
class-attribute
instance-attribute
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
key: str
property
¶
name: str
property
¶
parent: Self
property
¶
parents: Tuple[Self, ...]
property
¶
parser: Self
property
¶
parts: Tuple[str, ...]
property
¶
stem: str
property
¶
suffix: str
property
¶
suffixes: List[str]
property
¶
Methods:¶
__init__(cloud_path: Union[str, Self, CloudPath], *parts: str, client: Optional[Client] = None) -> None
¶
Source code in cloudpathlib/cloudpath.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
1102 1103 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
478 479 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 463 464 465 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1615 1616 1617 1618 1619 1620 1621 | |
copy(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy(
target: Self,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy(
target: Path,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy(
target: str,
follow_symlinks=True,
preserve_metadata=False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self to target folder or file, if self is a file.
Source code in cloudpathlib/cloudpath.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
copy_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
copy_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
copy_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
copy_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Copy self into target directory, preserving the filename.
Source code in cloudpathlib/cloudpath.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | |
copytree(destination, force_overwrite_to_cloud=None, ignore=None)
¶
copytree(
destination: Self,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Self
copytree(
destination: Path,
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Path
copytree(
destination: Union[str, os.PathLike, Self],
force_overwrite_to_cloud: Optional[bool] = None,
ignore: Optional[
Callable[[str, Iterable[str]], Container[str]]
] = None,
) -> Union[Path, CloudPath]
Copy self to a directory, if self is a directory.
Source code in cloudpathlib/cloudpath.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
481 482 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
494 495 496 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | |
glob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1253 1254 1255 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
15 16 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/local/localpath.py
18 19 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
1049 1050 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1128 1129 1130 1131 1132 1133 | |
is_valid_cloudpath(path: Union[str, CloudPath], raise_on_error: bool = False) -> Union[bool, TypeGuard[Self]]
classmethod
¶
is_valid_cloudpath(
path: CloudPath, raise_on_error: bool = ...
) -> TypeGuard[Self]
is_valid_cloudpath(
path: str, raise_on_error: bool = ...
) -> bool
Source code in cloudpathlib/cloudpath.py
358 359 360 361 362 363 364 365 366 367 368 369 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
599 600 601 602 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1099 1100 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/implementations/s3.py
37 38 39 | |
move(target: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move(
target: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move(
target: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move(
target: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self to target location, removing the source.
Source code in cloudpathlib/cloudpath.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 | |
move_into(target_dir: Union[str, os.PathLike, Self], follow_symlinks: bool = True, preserve_metadata: bool = False, force_overwrite_to_cloud: Optional[bool] = None) -> Union[Path, Self]
¶
move_into(
target_dir: Self,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Self
move_into(
target_dir: Path,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Path
move_into(
target_dir: str,
follow_symlinks: bool = True,
preserve_metadata: bool = False,
force_overwrite_to_cloud: Optional[bool] = None,
) -> Union[Path, CloudPath]
Move self into target directory, preserving the filename and removing the source.
Source code in cloudpathlib/cloudpath.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
open(mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, force_overwrite_from_cloud: Optional[bool] = None, force_overwrite_to_cloud: Optional[bool] = None, buffer_size: Optional[int] = None) -> IO[Any]
¶
open(
mode: OpenTextMode = "r",
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> TextIOWrapper
open(
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> FileIO
open(
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedRandom
open(
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedWriter
open(
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BufferedReader
open(
mode: OpenBinaryMode,
buffering: int = -1,
encoding: None = None,
errors: None = None,
newline: None = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> BinaryIO
open(
mode: str,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
force_overwrite_from_cloud: Optional[bool] = None,
force_overwrite_to_cloud: Optional[bool] = None,
buffer_size: Optional[int] = None,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
1036 1037 1038 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
1040 1041 1042 1043 1044 1045 1046 1047 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
976 977 978 979 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1108 1109 | |
rglob(pattern: Union[str, os.PathLike], case_sensitive: Optional[bool] = None, recurse_symlinks: bool = True) -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
981 982 983 984 985 986 987 988 989 990 991 992 993 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1280 1281 1282 1283 1284 1285 1286 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
995 996 997 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/local/localpath.py
21 22 23 24 25 26 27 28 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/local/localpath.py
30 31 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
999 1000 1001 1002 1003 1004 1005 | |
upload_from(source: Union[str, os.PathLike], force_overwrite_to_cloud: Optional[bool] = None) -> Self
¶
Upload a file or directory to the cloud path.
Source code in cloudpathlib/cloudpath.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
validate(v: str) -> Self
classmethod
¶
Used as a Pydantic validator. See https://docs.pydantic.dev/2.0/usage/types/custom/
Source code in cloudpathlib/cloudpath.py
1777 1778 1779 1780 1781 | |
walk(top_down: bool = True, on_error: Optional[Callable] = None, follow_symlinks: bool = False, lazy: bool = False) -> Generator[Tuple[Self, List[str], List[str]], None, None]
¶
Walk the directory tree rooted at this path, similar to
:meth:pathlib.Path.walk and :func:os.walk.
By default (lazy=False) the entire subtree is listed up front with a
single recursive listing, which is the fastest option for a full walk on
cloud backends.
Pass lazy=True to defer listing until each directory is visited (one
non-recursive listing per directory). This is slower for a full walk,
but lets callers prune dirnames in place (when top_down=True) to
avoid fetching the contents of skipped subtrees entirely -- which can be
dramatically faster and cheaper for sparse traversals.
follow_symlinks is accepted for signature parity with pathlib
but has no effect on cloud backends, which do not have symlinks.
Source code in cloudpathlib/cloudpath.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1209 1210 | |
with_segments(*pathsegments) -> Self
¶
Create a new CloudPath with the same client out of the given segments. The first segment will be interpreted as the bucket/container name.
Source code in cloudpathlib/cloudpath.py
1212 1213 1214 1215 1216 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1202 1203 1204 1205 1206 1207 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1218 1219 | |
write_bytes(data: bytes) -> int
¶
Open the file in bytes mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1235-L1242
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
¶
Open the file in text mode, write to it, and close the file.
NOTE: vendored from pathlib since we override open https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
Source code in cloudpathlib/cloudpath.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |