lamindb.UPath#
- class lamindb.UPath(*args: str | PathLike, **kwargs: Any)#
Bases:
Path
Paths: low-level key-value access to files/objects.
- Paths are based on keys that offer the typical access patterns of file systems
and object stores.
>>> upath = UPath("s3://my-bucket/my-folder") >>> upath.exists()
- Parameters:
pathlike – A string or Path to a local/cloud file/directory/folder.
Attributes
- anchor property#
The concatenation of the drive and root, or ‘’.
- drive property#
The drive prefix (letter or UNC path), if any.
- fs AbstractFileSystem#
The filesystem_spec filesystem instance
- modified datetime | None#
Return modified time stamp.
- name property#
The final path component, if any.
- parent PT#
The logical parent of the path.
- parents _UPathParents#
A sequence of this upath’s logical parents.
- parts property#
An object providing sequence-like access to the components in the filesystem path.
- path str#
The filesystem_spec path for use with a filesystem instance
Note: for some file systems this can be prefixed by the protocol.
- protocol str#
The filesystem_spec protocol
For local paths protocol is either ‘file’ if the UPath instance is backed by fsspec or ‘’ if it’s backed by stdlib pathlib. For both
fsspec.get_filesystem_class
returnsLocalFileSystem
.
- root property#
The root of the path, if any.
- stem property#
The final path component, minus its last suffix.
- storage_options dict[str, Any]#
The filesystem_spec storage options dictionary
Accessing
.storage_options
does not instantiate the corresponding fsspec filesystem class.
- suffix property#
The final component’s last suffix, if any.
This includes the leading period. For example: ‘.txt’
- suffixes property#
A list of the final component’s suffixes, if any.
These include the leading periods. For example: [‘.tar’, ‘.gz’]
Methods
- absolute()#
TypeVar
(PT
, bound= UPath)
- as_uri()#
str
- chmod(mode, *, follow_symlinks=True)#
None
- classmethod cwd()#
- download_to(path, print_progress=False, **kwargs)#
Download to a path.
- exists()#
Whether this path exists.
bool
- expanduser()#
- glob(pattern)#
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
Generator
[TypeVar
(PT
, bound= UPath),None
,None
]
- group()#
- hardlink_to(target)#
- classmethod home()#
- is_absolute()#
bool
- is_block_device()#
bool
- is_char_device()#
bool
- is_dir()#
Whether this path is a directory.
bool
- is_fifo()#
bool
- is_file()#
Whether this path is a regular file (also True for symlinks pointing to regular files).
bool
- is_mount()#
bool
- is_socket()#
bool
- is_symlink()#
bool
- iterdir()#
Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.
Generator
[TypeVar
(PT
, bound= UPath),None
,None
]
- lchmod(mode)#
- link_to(target)#
- lstat()#
- mkdir(mode=511, parents=False, exist_ok=False)#
Create a new directory at this given path.
None
- open(*args, **kwargs)#
- owner()#
- readlink()#
- relative_to(*other)#
Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.
TypeVar
(PT
, bound= UPath)
- rename(target, recursive=False, maxdepth=None, **kwargs)#
Move file, see fsspec.AbstractFileSystem.mv.
>>> upath = Upath("s3://my-bucket/my-file") >>> upath.rename(UPath("s3://my-bucket/my-file-renamed")) >>> upath.rename("my-file-renamed")
>>> upath = Upath("local-folder/my-file") >>> upath.rename("local-folder/my-file-renamed")
- replace(target)#
- resolve(strict=False)#
Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows).
TypeVar
(PT
, bound= UPath)
- rglob(pattern)#
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
Generator
[TypeVar
(PT
, bound= UPath),None
,None
]
- rmdir(recursive=True)#
None
- samefile(other_path)#
bool
- stat()#
Return the result of the stat() system call on this path, like os.stat() does.
- symlink_to(target, target_is_directory=False)#
- synchronize(objectpath, error_no_origin=True, print_progress=False, callback=None, **kwargs)#
Sync to a local destination path.
- to_url()#
Public storage URL.
Generates a public URL for an object in an S3 bucket using fsspec’s UPath, considering the bucket’s region.
Args: - upath: A UPath object representing an S3 path.
Returns: - A string containing the public URL to the S3 object.
- touch(*args, truncate=True, **kwargs)#
None
- unlink(missing_ok=False)#
Remove this file or link. If the path is a directory, use rmdir() instead.
None
- upload_from(path, dir_inplace=False, print_progress=False, **kwargs)#
Upload from a local path.
- view_tree(*, level=2, only_dirs=False, n_max_files_per_dir_and_type=100, n_max_files=1000, include_paths=None, skip_suffixes=None)#
Print a visual tree structure of files & directories.
- Parameters:
level (
int
, default:2
) – If 1, only iterate through one level, if 2 iterate through 2 levels, if -1 iterate through entire hierarchy.only_dirs (
bool
, default:False
) – Only iterate through directories.n_max_files (
int
, default:1000
) – Display limit. Will only show this many files. Doesn’t affect count.include_paths (
Optional
[set
[Any
]], default:None
) – Restrict to these paths.skip_suffixes (
Optional
[list
[str
]], default:None
) – Skip directories with these suffixes.
- Return type:
None
Examples
>>> dir_path = ln.core.datasets.generate_cell_ranger_files( >>> "sample_001", ln.settings.storage >>> ) >>> ln.UPath(dir_path).view_tree() 3 subdirectories, 15 files sample_001 ├── web_summary.html ├── metrics_summary.csv ├── molecule_info.h5 ├── filtered_feature_bc_matrix │ ├── features.tsv.gz │ ├── barcodes.tsv.gz │ └── matrix.mtx.gz ├── analysis │ └── analysis.csv ├── raw_feature_bc_matrix │ ├── features.tsv.gz │ ├── barcodes.tsv.gz │ └── matrix.mtx.gz ├── possorted_genome_bam.bam.bai ├── cloupe.cloupe ├── possorted_genome_bam.bam ├── filtered_feature_bc_matrix.h5 └── raw_feature_bc_matrix.h5
- with_name(name)#
Return a new path with the file name changed.
TypeVar
(PT
, bound= UPath)
- with_suffix(suffix)#
Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.
TypeVar
(PT
, bound= UPath)