ts_shape.loader.timeseries.azure_blob_loader
| Name | Description |
|---|---|
AzureBlobParquetLoader | Load parquet files from an Azure Blob Storage container filtered by a list of UUIDs. |
AzureBlobFlexibleFileLoader | Load arbitrary file types from Azure Blob Storage under time-structured folders. |
AzureBlobParquetLoader
AzureBlobParquetLoader(
container_name: str | None = None,
*,
connection_string: str | None = None,
account_url: str | None = None,
credential: Any | None = None,
sas_url: str | None = None,
prefix: str = "",
max_workers: int = 8,
hour_pattern: str = "{Y}/{m}/{d}/{H}/"
) -> None
Load parquet files from an Azure Blob Storage container filtered by a list of UUIDs.
Optimized for speed by:
- Using server-side prefix filtering when provided
- Streaming blob listings and filtering client-side by UUID containment
- Downloading and parsing parquet files concurrently
Hour folders are UTC: a tz-aware time bound is converted to UTC before the folders to visit are chosen, and a naive bound is read as UTC.
| Name | Description |
|---|---|
from_account_name | Construct a loader using AAD credentials with an account name. |
load_all_files | Load all parquet blobs in the container (optionally under prefix). |
load_by_time_range | Load all parquet blobs under hourly folders within [start, end]. |
stream_by_time_range | Stream parquet DataFrames under hourly folders within [start, end]. |
load_files_by_time_range_and_uuids | Load parquet blobs for given UUIDs within [start, end] hours. |
stream_files_by_time_range_and_uuids | Stream parquet DataFrames for given UUIDs within [start, end] hours. |
list_structure | List folder prefixes (hours) and blob names under the configured prefix. |
Supports three authentication methods:
-
SAS URL (simplest)::
loader = AzureBlobParquetLoader( sas_url="https://account.blob.core.windows.net/container?sv=...&sig=..." )
A SAS URL is also auto-detected when passed as
connection_string. -
Connection string::
loader = AzureBlobParquetLoader( connection_string="DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...", container_name="mycontainer", )
-
AAD credential (account_url + credential)::
loader = AzureBlobParquetLoader( account_url="https://account.blob.core.windows.net", container_name="mycontainer", credential=DefaultAzureCredential(), )
| Name | Type | Description | Default |
|---|---|---|---|
container_name | str | None | Target container name (not needed when using sas_url). | None |
connection_string | str | None | Azure Storage connection string. | None |
account_url | str | None | Full account URL for AAD auth. | None |
credential | Any | None | Azure credential object for AAD auth. | None |
sas_url | str | None | Full Blob SAS URL including container and SAS token. | None |
prefix | str | Optional path prefix to narrow listing (e.g. "year/month/"). | '' |
max_workers | int | Max concurrent downloads/reads. | 8 |
hour_pattern | str | Pattern for hour-level subpath; tokens: {Y} {m} {d} {H}. | '{Y}/{m}/{d}/{H}/' |
from_account_name
from_account_name(
account_name: str,
container_name: str,
*,
credential: Any | None = None,
endpoint_suffix: str = "blob.core.windows.net",
prefix: str = "",
max_workers: int = 8
) -> Self
Construct a loader using AAD credentials with an account name.
| Name | Type | Description | Default |
|---|---|---|---|
account_name | str | Storage account name. | required |
container_name | str | Target container. | required |
credential | Any | None | Optional Azure credential (DefaultAzureCredential if None). | None |
endpoint_suffix | str | DNS suffix for the blob endpoint (e.g., for sovereign clouds). | 'blob.core.windows.net' |
prefix | str | Optional listing prefix (e.g., "parquet/"). | '' |
max_workers | int | Concurrency for downloads. | 8 |
load_all_files
load_all_files(
columns: list[str] | None = None,
filters: list | None = None,
*,
errors: ErrorsMode = "warn"
) -> pd.DataFrame
Load all parquet blobs in the container (optionally under prefix).
| Name | Type | Description | Default |
|---|---|---|---|
columns | list[str] | None | Subset of parquet columns to read; None reads all columns. | None |
filters | list | None | pyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows. | None |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
| Type | Description |
|---|---|
DataFrame | A concatenated DataFrame of all parquet blobs. Returns an empty DataFrame |
DataFrame | if none are found. |
load_by_time_range
load_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
columns: list[str] | None = None,
filters: list | None = None,
*,
trim_to_range: bool = True,
errors: ErrorsMode = "warn"
) -> pd.DataFrame
Load all parquet blobs under hourly folders within [start, end].
Assumes container structure: prefix/year/month/day/hour/{file}.parquet Listing is constrained per-hour for speed.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts). Every hour folder that overlaps [start, end] is read in full (the start is floored to the hour); see trim_to_range. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
columns | list[str] | None | Subset of parquet columns to read; None reads all columns. | None |
filters | list | None | pyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows. | None |
trim_to_range | bool | If True (default), drop rows whose systime falls outside [start, end] (both bounds inclusive). Frames without a systime column are left as read. False keeps whole hour folders. | True |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
stream_by_time_range
stream_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
columns: list[str] | None = None,
filters: list | None = None,
*,
trim_to_range: bool = True,
errors: ErrorsMode = "warn"
) -> Iterator[tuple[str, pd.DataFrame]]
Stream parquet DataFrames under hourly folders within [start, end].
Yields (blob_name, DataFrame) one by one to avoid holding everything in memory.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts). Every hour folder that overlaps [start, end] is read in full (the start is floored to the hour); see trim_to_range. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
columns | list[str] | None | Subset of parquet columns to read; None reads all columns. | None |
filters | list | None | pyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows. | None |
trim_to_range | bool | If True (default), drop rows whose systime falls outside [start, end] (both bounds inclusive). Frames without a systime column are left as read. False keeps whole hour folders. | True |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
load_files_by_time_range_and_uuids
load_files_by_time_range_and_uuids(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
uuid_list: list[str],
columns: list[str] | None = None,
filters: list | None = None,
*,
trim_to_range: bool = True,
errors: ErrorsMode = "warn"
) -> pd.DataFrame
Load parquet blobs for given UUIDs within [start, end] hours.
Strategy:
- List each hour prefix once and keep blobs whose basename matches a requested UUID variant. When listing succeeds it is authoritative, so only blobs that actually exist are downloaded.
- Only when listing fails entirely (e.g. a SAS token without list permission) fall back to constructing direct blob paths assuming the pattern prefix/YYYY/MM/DD/HH/{uuid}.parquet and downloading those blindly.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts). Every hour folder that overlaps [start, end] is read in full (the start is floored to the hour); see trim_to_range. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
uuid_list | list[str] | Signal UUIDs to load; each matches a <uuid>.parquet file. Surrounding whitespace and braces are stripped and a lowercase variant is also tried. | required |
columns | list[str] | None | Subset of parquet columns to read; None reads all columns. | None |
filters | list | None | pyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows. | None |
trim_to_range | bool | If True (default), drop rows whose systime falls outside [start, end] (both bounds inclusive). Frames without a systime column are left as read. False keeps whole hour folders. | True |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
stream_files_by_time_range_and_uuids
stream_files_by_time_range_and_uuids(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
uuid_list: list[str],
columns: list[str] | None = None,
filters: list | None = None,
*,
trim_to_range: bool = True,
errors: ErrorsMode = "warn"
) -> Iterator[tuple[str, pd.DataFrame]]
Stream parquet DataFrames for given UUIDs within [start, end] hours.
Yields (blob_name, DataFrame) as they arrive. Listing is authoritative
when available; direct blob names are used only as a fallback when
listing fails (see :meth:load_files_by_time_range_and_uuids).
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts). Every hour folder that overlaps [start, end] is read in full (the start is floored to the hour); see trim_to_range. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
uuid_list | list[str] | Signal UUIDs to load; each matches a <uuid>.parquet file. Surrounding whitespace and braces are stripped and a lowercase variant is also tried. | required |
columns | list[str] | None | Subset of parquet columns to read; None reads all columns. | None |
filters | list | None | pyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows. | None |
trim_to_range | bool | If True (default), drop rows whose systime falls outside [start, end] (both bounds inclusive). Frames without a systime column are left as read. False keeps whole hour folders. | True |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
list_structure
list_structure(
only_parquet: bool = True, limit: int | None = None
) -> dict[str, list[str]]
List folder prefixes (hours) and blob names under the configured prefix.
| Name | Type | Description | Default |
|---|---|---|---|
only_parquet | bool | If True, only include blobs ending with .parquet. | True |
limit | int | None | Optional cap on number of files collected for quick inspection. | None |
| Type | Description |
|---|---|
dict[str, list[str]] | A dict with: |
dict[str, list[str]] | - folders: Sorted unique hour-level prefixes like 'parquet/YYYY/MM/DD/HH/' |
dict[str, list[str]] | - files: Sorted blob names (full paths) matching the filter |
AzureBlobFlexibleFileLoader
AzureBlobFlexibleFileLoader(
container_name: str | None = None,
*,
connection_string: str | None = None,
account_url: str | None = None,
credential: Any | None = None,
sas_url: str | None = None,
prefix: str = "",
max_workers: int = 8,
hour_pattern: str = "{Y}/{m}/{d}/{H}/"
) -> None
Load arbitrary file types from Azure Blob Storage under time-structured folders.
Designed for containers with paths like: prefix/YYYY/MM/DD/HH/
Hour folders are UTC: a tz-aware time bound is converted to UTC before the folders to visit are chosen, and a naive bound is read as UTC.
| Name | Description |
|---|---|
register_parser | Register a parser for a file extension, replacing any existing one. |
unregister_parser | Remove the parser for a file extension, if one is registered. |
available_parsers | Return the set of file extensions that have a registered parser. |
list_files_by_time_range | List blob names under each hourly prefix within [start, end]. |
iter_file_names_by_time_range | Yield blob names under each hourly prefix within [start, end]. |
fetch_files_by_time_range | Download files that match extensions within [start, end] hour prefixes. |
stream_files_by_time_range | Stream matching files as (blob_name, bytes-or-parsed) within [start, end]. |
fetch_files_by_time_range_and_basenames | Download files whose basename (final path segment) is in basenames, |
stream_files_by_time_range_and_basenames | Stream files whose basename is in basenames within [start, end]. |
Supports SAS URL, connection string, and AAD credential auth.
See :class:AzureBlobParquetLoader for full parameter docs.
A SAS URL is auto-detected when passed as connection_string.
| Name | Type | Description | Default |
|---|---|---|---|
container_name | str | None | Target container name (not needed when using sas_url). | None |
connection_string | str | None | Azure Storage connection string. A value starting with http is treated as sas_url. | None |
account_url | str | None | Full account URL for AAD auth (used with credential). | None |
credential | Any | None | Azure credential object for AAD auth. | None |
sas_url | str | None | Full Blob SAS URL including container and SAS token. | None |
prefix | str | Path prefix prepended to every hour folder (e.g. "raw/"). Default "". | '' |
max_workers | int | Maximum concurrent downloads; values below 1 are treated as 1. Default 8. | 8 |
hour_pattern | str | Pattern for the hour-level subpath, with tokens {Y} {m} {d} {H}. Default "{Y}/{m}/{d}/{H}/". | '{Y}/{m}/{d}/{H}/' |
register_parser
register_parser(extension: str, func: Callable[[bytes, str], Any]) -> None
Register a parser for a file extension, replacing any existing one.
| Name | Type | Description | Default |
|---|---|---|---|
extension | str | File extension, with or without the leading dot (case-insensitive). | required |
func | Callable[[bytes, str], Any] | Callable receiving the blob content and blob name and returning the parsed object. | required |
unregister_parser
unregister_parser(extension: str) -> None
Remove the parser for a file extension, if one is registered.
| Name | Type | Description | Default |
|---|---|---|---|
extension | str | File extension, with or without the leading dot (case-insensitive). | required |
available_parsers
available_parsers() -> set[str]
Return the set of file extensions that have a registered parser.
list_files_by_time_range
list_files_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
*,
extensions: Iterable[str] | None = None,
limit: int | None = None
) -> list[str]
List blob names under each hourly prefix within [start, end].
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
extensions | Iterable[str] | None | Optional set/list of file extensions (e.g., {"json", ".bmp"}). Case-insensitive. | None |
limit | int | None | Optional cap on number of files collected. | None |
iter_file_names_by_time_range
iter_file_names_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
*,
extensions: Iterable[str] | None = None
) -> Iterator[str]
Yield blob names under each hourly prefix within [start, end]. Uses server-side prefix listing and client-side extension filtering.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
extensions | Iterable[str] | None | File extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file. | None |
fetch_files_by_time_range
fetch_files_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
*,
extensions: Iterable[str] | None = None,
parse: bool = False,
errors: ErrorsMode = "warn"
) -> dict[str, Any]
Download files that match extensions within [start, end] hour prefixes. Returns a dict mapping blob_name -> parsed object (if parse=True and a parser exists), otherwise raw bytes.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
extensions | Iterable[str] | None | File extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file. | None |
parse | bool | If True, parse each file with the parser registered for its extension (see register_parser), falling back to raw bytes when none exists or parsing fails (with a :class:~ts_shape.errors.DataQualityWarning). Default False returns raw bytes. | False |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
stream_files_by_time_range
stream_files_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
*,
extensions: Iterable[str] | None = None,
parse: bool = False,
errors: ErrorsMode = "warn"
) -> Iterator[tuple[str, Any]]
Stream matching files as (blob_name, bytes-or-parsed) within [start, end].
Maintains up to max_workers concurrent downloads while yielding incrementally.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
extensions | Iterable[str] | None | File extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file. | None |
parse | bool | If True, parse each file with the parser registered for its extension (see register_parser), falling back to raw bytes when none exists or parsing fails (with a :class:~ts_shape.errors.DataQualityWarning). Default False returns raw bytes. | False |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
fetch_files_by_time_range_and_basenames
fetch_files_by_time_range_and_basenames(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
basenames: Iterable[str],
*,
extensions: Iterable[str] | None = None,
parse: bool = False,
errors: ErrorsMode = "warn"
) -> dict[str, Any]
Download files whose basename (final path segment) is in basenames,
optionally filtered by extensions, within [start, end] hour prefixes.
Returns blob_name -> parsed object (if parse=True and a parser exists), otherwise raw bytes.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
basenames | Iterable[str] | File names (final path segment, extension included) to keep; matched exactly, after stripping whitespace. | required |
extensions | Iterable[str] | None | File extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file. | None |
parse | bool | If True, parse each file with the parser registered for its extension (see register_parser), falling back to raw bytes when none exists or parsing fails (with a :class:~ts_shape.errors.DataQualityWarning). Default False returns raw bytes. | False |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |
stream_files_by_time_range_and_basenames
stream_files_by_time_range_and_basenames(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
basenames: Iterable[str],
*,
extensions: Iterable[str] | None = None,
parse: bool = False,
errors: ErrorsMode = "warn"
) -> Iterator[tuple[str, Any]]
Stream files whose basename is in basenames within [start, end].
Yields (blob_name, bytes-or-parsed) incrementally with bounded concurrency.
| Name | Type | Description | Default |
|---|---|---|---|
start | str | Timestamp | Start of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed. | required |
end | str | Timestamp | End of the range, inclusive (anything pd.to_datetime accepts). | required |
basenames | Iterable[str] | File names (final path segment, extension included) to keep; matched exactly, after stripping whitespace. | required |
extensions | Iterable[str] | None | File extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file. | None |
parse | bool | If True, parse each file with the parser registered for its extension (see register_parser), falling back to raw bytes when none exists or parsing fails (with a :class:~ts_shape.errors.DataQualityWarning). Default False returns raw bytes. | False |
errors | ErrorsMode | "warn" (default) skips a blob that cannot be downloaded and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped blob; "raise" raises :class:~ts_shape.errors.LoaderError instead. | 'warn' |