dlt.sources.filesystem
Reads files in s3, gs or azure buckets using fsspec and provides convenience resources for chunked reading of various file formats
readers
@decorators.source(_impl_cls=ReadersSource,
spec=FilesystemConfigurationResource)
def readers(
bucket_url: str = dlt.secrets.value,
credentials: Union[FileSystemCredentials,
AbstractFileSystem] = dlt.secrets.value,
file_glob: str = "*",
kwargs: Optional[Dict[str, Any]] = None,
client_kwargs: Optional[Dict[str, Any]] = None,
incremental: Optional[dlt.sources.incremental[Any]] = None
) -> Tuple[DltResource, ...]
This source provides a few resources that are chunked file readers. Readers can be further parametrized before use read_csv(chunksize, **pandas_kwargs) read_jsonl(chunksize) read_parquet(chunksize)
Arguments:
bucket_url
str - The url to the bucket.credentials
Union[FileSystemCredentials, AbstractFileSystem] - The credentials to the filesystem of fsspecAbstractFilesystem
instance.file_glob
str, optional - The filter to apply to the files in glob format. by default lists all files in bucket_url non-recursivelykwargs
- (Optional[Dict[str, Any]], optional): Additional arguments passed to fsspec constructor ie. dict(use_ssl=True) for s3fsclient_kwargs
- (Optional[Dict[str, Any]], optional): Additional arguments passed to underlying fsspec native client ie. dict(verify="public.crt) for botocoreincremental
Optional[dlt.sources.incremental[Any]] - Defines incremental cursor on listed files, withmodification_date
being the most common choice that returns only files created from the previous run.
Returns:
Tuple[DltResource, ...]: A tuple of resources that are chunked file readers.
filesystem
@decorators.resource(primary_key="file_url",
spec=FilesystemConfigurationResource)
def filesystem(
bucket_url: str = dlt.secrets.value,
credentials: Union[FileSystemCredentials,
AbstractFileSystem] = dlt.secrets.value,
file_glob: str = "*",
files_per_page: int = DEFAULT_CHUNK_SIZE,
extract_content: bool = False,
kwargs: Optional[Dict[str, Any]] = None,
client_kwargs: Optional[Dict[str, Any]] = None,
incremental: Optional[dlt.sources.incremental[Any]] = None
) -> Iterator[List[FileItem]]
This resource lists files in bucket_url
using file_glob
pattern. The files are yielded as FileItem which also
provide methods to open and read file data. It should be combined with transformers that further process (ie. load files)
Arguments:
bucket_url
str - The url to the bucket.credentials
Union[FileSystemCredentials, AbstractFileSystem] - The credentials to the filesystem of fsspecAbstractFilesystem
instance.file_glob
str - The filter to apply to the files in glob format. by default lists all files in bucket_url non-recursivelyfiles_per_page
int, optional - The number of files to process at once, defaults to 100.extract_content
bool, optional - If true, the content of the file will be extracted if false it will return a fsspec file, defaults to False.kwargs
Optional[Dict[str, Any]] - Additional arguments passed to fsspec constructor ie. dict(use_ssl=True) for s3fsclient_kwargs
Optional[Dict[str, Any]] - Additional arguments passed to underlying fsspec native client ie. dict(verify="public.crt) for botocoreincremental
Optional[dlt.sources.incremental[Any]] - Defines incremental cursor on listed files, withmodification_date
being the most common choice that returns only files created from the previous run.
Yields:
List[FileItem]
- The list of files.