cloudpathlib.GSPath¶
Bases: CloudPath
Class for representing and operating on Google Cloud Storage URIs, in the style of the
Python standard library's pathlib module.
Instances represent a path in GS with filesystem path semantics, and convenient methods allow
for basic operations like joining, reading, writing, iterating over contents, etc. This class
almost entirely mimics the pathlib.Path
interface, so most familiar properties and methods should be available and behave in the
expected way.
The GSClient class handles authentication with GCP. If a client instance is
not explicitly specified on GSPath instantiation, a default client is used. See GSClient's
documentation for more details.
Source code in cloudpathlib/gs/gspath.py
12 13 14 15 16 17 18 19 20 21 22 23 24 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 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 | |
Attributes¶
anchor: str
property
¶
blob: str
property
¶
bucket: str
property
¶
client: GSClient
instance-attribute
¶
cloud_prefix: str = 'gs://'
class-attribute
instance-attribute
¶
drive: str
property
¶
etag
property
¶
fspath: str
property
¶
md5: Optional[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
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 | |
absolute() -> Self
¶
Source code in cloudpathlib/cloudpath.py
998 999 | |
as_uri() -> str
¶
Source code in cloudpathlib/cloudpath.py
444 445 | |
as_url(presign: bool = False, expire_seconds: int = 60 * 60) -> str
¶
Source code in cloudpathlib/cloudpath.py
426 427 428 429 430 431 | |
clear_cache()
¶
Removes cache if it exists
Source code in cloudpathlib/cloudpath.py
1511 1512 1513 1514 1515 1516 1517 | |
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
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 | |
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
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 | |
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
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 | |
download_to(destination: Union[str, os.PathLike]) -> Path
¶
Source code in cloudpathlib/cloudpath.py
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | |
exists(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
447 448 | |
from_uri(uri: str) -> Self
classmethod
¶
Source code in cloudpathlib/cloudpath.py
460 461 462 | |
full_match(pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | |
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
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
info() -> CloudPathInfo
¶
Return a CloudPathInfo object for this path.
Source code in cloudpathlib/cloudpath.py
1149 1150 1151 | |
is_absolute() -> bool
¶
Source code in cloudpathlib/cloudpath.py
1001 1002 | |
is_dir(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
450 451 | |
is_file(follow_symlinks=True) -> bool
¶
Source code in cloudpathlib/cloudpath.py
453 454 | |
is_junction()
¶
Source code in cloudpathlib/cloudpath.py
945 946 | |
is_relative_to(other: Self) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1024 1025 1026 1027 1028 1029 | |
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
332 333 334 335 336 337 338 339 340 341 342 343 | |
iterdir() -> Generator[Self, None, None]
¶
Source code in cloudpathlib/cloudpath.py
565 566 567 568 | |
joinpath(*pathsegments: Union[str, os.PathLike]) -> Self
¶
Source code in cloudpathlib/cloudpath.py
995 996 | |
match(path_pattern: str, case_sensitive: Optional[bool] = None) -> bool
¶
Source code in cloudpathlib/cloudpath.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 | |
mkdir(parents=False, exist_ok=False, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/gs/gspath.py
34 35 36 | |
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
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | |
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
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | |
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) -> 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,
) -> 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,
) -> 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,
) -> 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,
) -> 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,
) -> 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,
) -> 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,
) -> IO[Any]
Source code in cloudpathlib/cloudpath.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 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 | |
read_bytes() -> bytes
¶
Source code in cloudpathlib/cloudpath.py
932 933 934 | |
read_text(encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
¶
Source code in cloudpathlib/cloudpath.py
936 937 938 939 940 941 942 943 | |
relative_to(other: Self, walk_up: bool = False) -> PurePosixPath
¶
Source code in cloudpathlib/cloudpath.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 | |
rename(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
872 873 874 875 | |
replace(target: Self) -> Self
¶
Source code in cloudpathlib/cloudpath.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
resolve(strict: bool = False) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1004 1005 | |
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
550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
rmdir() -> None
¶
Source code in cloudpathlib/cloudpath.py
877 878 879 880 881 882 883 884 885 886 887 888 889 | |
rmtree() -> None
¶
Delete an entire directory tree.
Source code in cloudpathlib/cloudpath.py
1176 1177 1178 1179 1180 1181 1182 | |
samefile(other_path: Union[str, os.PathLike]) -> bool
¶
Source code in cloudpathlib/cloudpath.py
891 892 893 | |
stat(follow_symlinks=True)
¶
Source code in cloudpathlib/gs/gspath.py
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 | |
touch(exist_ok: bool = True, mode: Optional[Any] = None)
¶
Source code in cloudpathlib/gs/gspath.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
unlink(missing_ok: bool = True) -> None
¶
Source code in cloudpathlib/cloudpath.py
895 896 897 898 899 900 901 | |
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
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
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
1673 1674 1675 1676 1677 | |
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
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
with_name(name: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1105 1106 | |
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
1108 1109 1110 1111 1112 | |
with_stem(stem: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1098 1099 1100 1101 1102 1103 | |
with_suffix(suffix: str) -> Self
¶
Source code in cloudpathlib/cloudpath.py
1114 1115 | |
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
903 904 905 906 907 908 909 910 911 912 | |
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
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |