Skip to main content
Version: Next

ts_shape.loader.timeseries.azure_blob_loader

Classes
NameDescription
AzureBlobParquetLoaderLoad parquet files from an Azure Blob Storage container filtered by a list of UUIDs.
AzureBlobFlexibleFileLoaderLoad arbitrary file types from Azure Blob Storage under time-structured folders.

AzureBlobParquetLoader​

classsource
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.

Functions
NameDescription
from_account_nameConstruct a loader using AAD credentials with an account name.
load_all_filesLoad all parquet blobs in the container (optionally under prefix).
load_by_time_rangeLoad all parquet blobs under hourly folders within [start, end].
stream_by_time_rangeStream parquet DataFrames under hourly folders within [start, end].
load_files_by_time_range_and_uuidsLoad parquet blobs for given UUIDs within [start, end] hours.
stream_files_by_time_range_and_uuidsStream parquet DataFrames for given UUIDs within [start, end] hours.
list_structureList folder prefixes (hours) and blob names under the configured prefix.

Supports three authentication methods:

  1. 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.

  2. Connection string::

    loader = AzureBlobParquetLoader( connection_string="DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...", container_name="mycontainer", )

  3. AAD credential (account_url + credential)::

    loader = AzureBlobParquetLoader( account_url="https://account.blob.core.windows.net", container_name="mycontainer", credential=DefaultAzureCredential(), )

Parameters
NameTypeDescriptionDefault
container_namestr | NoneTarget container name (not needed when using sas_url).None
connection_stringstr | NoneAzure Storage connection string.None
account_urlstr | NoneFull account URL for AAD auth.None
credentialAny | NoneAzure credential object for AAD auth.None
sas_urlstr | NoneFull Blob SAS URL including container and SAS token.None
prefixstrOptional path prefix to narrow listing (e.g. "year/month/").''
max_workersintMax concurrent downloads/reads.8
hour_patternstrPattern for hour-level subpath; tokens: {Y} {m} {d} {H}.'{Y}/{m}/{d}/{H}/'

from_account_name​

classmethodsource
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.

Parameters
NameTypeDescriptionDefault
account_namestrStorage account name.required
container_namestrTarget container.required
credentialAny | NoneOptional Azure credential (DefaultAzureCredential if None).None
endpoint_suffixstrDNS suffix for the blob endpoint (e.g., for sovereign clouds).'blob.core.windows.net'
prefixstrOptional listing prefix (e.g., "parquet/").''
max_workersintConcurrency for downloads.8

load_all_files​

methodsource
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).

Parameters
NameTypeDescriptionDefault
columnslist[str] | NoneSubset of parquet columns to read; None reads all columns.None
filterslist | Nonepyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows.None
errorsErrorsMode"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'
Returns
TypeDescription
DataFrameA concatenated DataFrame of all parquet blobs. Returns an empty DataFrame
DataFrameif none are found.

load_by_time_range​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart 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
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
columnslist[str] | NoneSubset of parquet columns to read; None reads all columns.None
filterslist | Nonepyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows.None
trim_to_rangeboolIf 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
errorsErrorsMode"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​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart 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
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
columnslist[str] | NoneSubset of parquet columns to read; None reads all columns.None
filterslist | Nonepyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows.None
trim_to_rangeboolIf 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
errorsErrorsMode"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​

methodsource
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:

  1. 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.
  2. 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.
Parameters
NameTypeDescriptionDefault
startstr | TimestampStart 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
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
uuid_listlist[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
columnslist[str] | NoneSubset of parquet columns to read; None reads all columns.None
filterslist | Nonepyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows.None
trim_to_rangeboolIf 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
errorsErrorsMode"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​

methodsource
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).

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart 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
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
uuid_listlist[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
columnslist[str] | NoneSubset of parquet columns to read; None reads all columns.None
filterslist | Nonepyarrow-style predicate pushdown in DNF form, e.g. [("value_double", ">", 0.0)]; None reads all rows.None
trim_to_rangeboolIf 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
errorsErrorsMode"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​

methodsource
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.

Parameters
NameTypeDescriptionDefault
only_parquetboolIf True, only include blobs ending with .parquet.True
limitint | NoneOptional cap on number of files collected for quick inspection.None
Returns
TypeDescription
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​

classsource
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//file.ext This class lists by per-hour prefix and can filter by extensions and/or basenames, then downloads files concurrently as raw bytes.

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.

Functions
NameDescription
register_parserRegister a parser for a file extension, replacing any existing one.
unregister_parserRemove the parser for a file extension, if one is registered.
available_parsersReturn the set of file extensions that have a registered parser.
list_files_by_time_rangeList blob names under each hourly prefix within [start, end].
iter_file_names_by_time_rangeYield blob names under each hourly prefix within [start, end].
fetch_files_by_time_rangeDownload files that match extensions within [start, end] hour prefixes.
stream_files_by_time_rangeStream matching files as (blob_name, bytes-or-parsed) within [start, end].
fetch_files_by_time_range_and_basenamesDownload files whose basename (final path segment) is in basenames,
stream_files_by_time_range_and_basenamesStream 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.

Parameters
NameTypeDescriptionDefault
container_namestr | NoneTarget container name (not needed when using sas_url).None
connection_stringstr | NoneAzure Storage connection string. A value starting with http is treated as sas_url.None
account_urlstr | NoneFull account URL for AAD auth (used with credential).None
credentialAny | NoneAzure credential object for AAD auth.None
sas_urlstr | NoneFull Blob SAS URL including container and SAS token.None
prefixstrPath prefix prepended to every hour folder (e.g. "raw/"). Default "".''
max_workersintMaximum concurrent downloads; values below 1 are treated as 1. Default 8.8
hour_patternstrPattern for the hour-level subpath, with tokens {Y} {m} {d} {H}. Default "{Y}/{m}/{d}/{H}/".'{Y}/{m}/{d}/{H}/'

register_parser​

classmethodsource
register_parser(extension: str, func: Callable[[bytes, str], Any]) -> None

Register a parser for a file extension, replacing any existing one.

Parameters
NameTypeDescriptionDefault
extensionstrFile extension, with or without the leading dot (case-insensitive).required
funcCallable[[bytes, str], Any]Callable receiving the blob content and blob name and returning the parsed object.required

unregister_parser​

classmethodsource
unregister_parser(extension: str) -> None

Remove the parser for a file extension, if one is registered.

Parameters
NameTypeDescriptionDefault
extensionstrFile extension, with or without the leading dot (case-insensitive).required

available_parsers​

classmethodsource
available_parsers() -> set[str]

Return the set of file extensions that have a registered parser.

list_files_by_time_range​

methodsource
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].

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed.required
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
extensionsIterable[str] | NoneOptional set/list of file extensions (e.g., {"json", ".bmp"}). Case-insensitive.None
limitint | NoneOptional cap on number of files collected.None

iter_file_names_by_time_range​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed.required
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
extensionsIterable[str] | NoneFile extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file.None

fetch_files_by_time_range​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed.required
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
extensionsIterable[str] | NoneFile extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file.None
parseboolIf 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
errorsErrorsMode"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​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed.required
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
extensionsIterable[str] | NoneFile extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file.None
parseboolIf 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
errorsErrorsMode"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​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed.required
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
basenamesIterable[str]File names (final path segment, extension included) to keep; matched exactly, after stripping whitespace.required
extensionsIterable[str] | NoneFile extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file.None
parseboolIf 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
errorsErrorsMode"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​

methodsource
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.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart of the range (anything pd.to_datetime accepts); hour folders from this hour on are listed.required
endstr | TimestampEnd of the range, inclusive (anything pd.to_datetime accepts).required
basenamesIterable[str]File names (final path segment, extension included) to keep; matched exactly, after stripping whitespace.required
extensionsIterable[str] | NoneFile extensions to keep, with or without the dot (e.g. {"json", ".bmp"}), case-insensitive. None keeps every file.None
parseboolIf 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
errorsErrorsMode"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'