contract.base¶
DataStream ¶
DataStream(
name: str,
*,
description: Optional[str] = None,
reader_params: Optional[TReaderParams] = None,
**kwargs,
)
Bases: ABC
, Generic[TData, TReaderParams]
Abstract base class for all data streams.
Provides a generic interface for data reading operations with configurable parameters and hierarchical organization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name identifier for the data stream. |
required |
description
|
Optional[str]
|
Optional description of the data stream. |
None
|
reader_params
|
Optional[TReaderParams]
|
Optional parameters for the data reader. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Attributes:
Name | Type | Description |
---|---|---|
_is_collection |
bool
|
Class variable indicating if this is a collection of data streams. |
Raises:
Type | Description |
---|---|
ValueError
|
If name contains '::' characters which are reserved for path resolution. |
Source code in src/contraqctor/contract/base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
name
property
¶
name: str
Get the name of the data stream.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Name identifier of the data stream. |
resolved_name
property
¶
resolved_name: str
Get the full hierarchical name of the data stream.
Generates a path-like name showing the stream's position in the hierarchy, using '::' as a separator between parent and child names.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The fully resolved name including all parent names. |
description
property
¶
parent
property
¶
parent: Optional[DataStream]
Get the parent data stream.
Returns:
Type | Description |
---|---|
Optional[DataStream]
|
Optional[DataStream]: Parent data stream, or None if this is a root stream. |
is_collection
property
¶
is_collection: bool
Check if this data stream is a collection of other streams.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if this is a collection stream, False otherwise. |
reader_params
property
¶
reader_params: TReaderParams
Get the parameters for the data reader.
Returns:
Name | Type | Description |
---|---|---|
TReaderParams |
TReaderParams
|
Parameters for the data reader. |
has_data
property
¶
has_data: bool
Check if the data stream has loaded data.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if data has been loaded, False otherwise. |
data
property
¶
data: TData
Get the loaded data.
Returns:
Name | Type | Description |
---|---|---|
TData |
TData
|
The loaded data. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
read ¶
read(
reader_params: Optional[TReaderParams] = None,
) -> TData
Read data using the configured reader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reader_params
|
Optional[TReaderParams]
|
Optional parameters to override the default reader parameters. |
None
|
Returns:
Name | Type | Description |
---|---|---|
TData |
TData
|
Data read from the source. |
Raises:
Type | Description |
---|---|
ValueError
|
If reader parameters are not set. |
Source code in src/contraqctor/contract/base.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
bind_reader_params ¶
bind_reader_params(params: TReaderParams) -> Self
Bind reader parameters to the data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
TReaderParams
|
Parameters to bind to the data stream's reader. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The data stream instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If reader parameters have already been set. |
Source code in src/contraqctor/contract/base.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
at ¶
at(name: str) -> DataStream
Get a child data stream by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the child data stream to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataStream |
DataStream
|
The child data stream with the given name. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the data stream does not support child access. |
Examples:
# Access stream in a collection
collection = data_collection.load()
temp_stream = collection.at("temperature")
# Or using dictionary-style syntax
humidity_stream = collection["humidity"]
Source code in src/contraqctor/contract/base.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
load ¶
load() -> Self
Load data into the data stream.
Reads data from the source and stores it in the data stream.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The data stream instance for method chaining. |
Examples:
from contraqctor.contract import csv
# Create and load a CSV stream
params = csv.CsvParams(path="data/measurements.csv")
csv_stream = csv.Csv("measurements", reader_params=params)
csv_stream.load()
# Access the data
df = csv_stream.data
print(f"Loaded {len(df)} rows")
Source code in src/contraqctor/contract/base.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
load_all ¶
load_all(
strict: bool = False,
) -> list[tuple[DataStream, Exception], None, None]
Recursively load this data stream and all child streams.
Performs depth-first traversal to load all streams in the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strict
|
bool
|
If True, raises exceptions immediately; otherwise collects and returns them. |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[tuple[DataStream, Exception], None, None]
|
List of tuples containing streams and exceptions that occurred during loading. |
Raises:
Type | Description |
---|---|
Exception
|
If strict is True and an exception occurs during loading. |
Examples:
# Load all streams and handle errors
errors = collection.load_all(strict=False)
if errors:
for stream, error in errors:
print(f"Error loading {stream.name}: {error}")
Source code in src/contraqctor/contract/base.py
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 284 285 286 287 288 289 290 291 292 293 294 |
|
DataStreamCollectionBase ¶
DataStreamCollectionBase(
name: str,
*,
description: Optional[str] = None,
reader_params: Optional[TReaderParams] = None,
**kwargs,
)
Bases: DataStream[List[TDataStream], TReaderParams]
, Generic[TDataStream, TReaderParams]
Base class for collections of data streams.
Provides functionality for managing and accessing multiple child data streams.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name identifier for the collection. |
required |
description
|
Optional[str]
|
Optional description of the collection. |
None
|
reader_params
|
Optional[TReaderParams]
|
Optional parameters for the reader. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Source code in src/contraqctor/contract/base.py
317 318 319 320 321 322 323 324 325 326 327 |
|
name
property
¶
name: str
Get the name of the data stream.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Name identifier of the data stream. |
resolved_name
property
¶
resolved_name: str
Get the full hierarchical name of the data stream.
Generates a path-like name showing the stream's position in the hierarchy, using '::' as a separator between parent and child names.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The fully resolved name including all parent names. |
description
property
¶
parent
property
¶
parent: Optional[DataStream]
Get the parent data stream.
Returns:
Type | Description |
---|---|
Optional[DataStream]
|
Optional[DataStream]: Parent data stream, or None if this is a root stream. |
is_collection
property
¶
is_collection: bool
Check if this data stream is a collection of other streams.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if this is a collection stream, False otherwise. |
reader_params
property
¶
reader_params: TReaderParams
Get the parameters for the data reader.
Returns:
Name | Type | Description |
---|---|---|
TReaderParams |
TReaderParams
|
Parameters for the data reader. |
has_data
property
¶
has_data: bool
Check if the data stream has loaded data.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if data has been loaded, False otherwise. |
data
property
¶
data: TData
Get the loaded data.
Returns:
Name | Type | Description |
---|---|---|
TData |
TData
|
The loaded data. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
load ¶
load()
Load data for this collection.
Overrides the base method to add validation that loaded data is a list of DataStreams.
Returns:
Name | Type | Description |
---|---|---|
Self |
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If loaded data is not a list of DataStreams. |
Source code in src/contraqctor/contract/base.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
at ¶
at(name: str) -> TDataStream
Get a child data stream by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the child data stream to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
TDataStream |
TDataStream
|
The child data stream with the given name. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
KeyError
|
If no child stream with the given name exists. |
Source code in src/contraqctor/contract/base.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
iter_all ¶
iter_all() -> Generator[DataStream, None, None]
Iterator for all child data streams, including nested collections.
Implements a depth-first traversal of the stream hierarchy.
Yields:
Name | Type | Description |
---|---|---|
DataStream |
DataStream
|
All recursively yielded child data streams. |
Source code in src/contraqctor/contract/base.py
436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
read ¶
read(
reader_params: Optional[TReaderParams] = None,
) -> TData
Read data using the configured reader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reader_params
|
Optional[TReaderParams]
|
Optional parameters to override the default reader parameters. |
None
|
Returns:
Name | Type | Description |
---|---|---|
TData |
TData
|
Data read from the source. |
Raises:
Type | Description |
---|---|
ValueError
|
If reader parameters are not set. |
Source code in src/contraqctor/contract/base.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
bind_reader_params ¶
bind_reader_params(params: TReaderParams) -> Self
Bind reader parameters to the data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
TReaderParams
|
Parameters to bind to the data stream's reader. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The data stream instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If reader parameters have already been set. |
Source code in src/contraqctor/contract/base.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
load_all ¶
load_all(
strict: bool = False,
) -> list[tuple[DataStream, Exception], None, None]
Recursively load this data stream and all child streams.
Performs depth-first traversal to load all streams in the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strict
|
bool
|
If True, raises exceptions immediately; otherwise collects and returns them. |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[tuple[DataStream, Exception], None, None]
|
List of tuples containing streams and exceptions that occurred during loading. |
Raises:
Type | Description |
---|---|
Exception
|
If strict is True and an exception occurs during loading. |
Examples:
# Load all streams and handle errors
errors = collection.load_all(strict=False)
if errors:
for stream, error in errors:
print(f"Error loading {stream.name}: {error}")
Source code in src/contraqctor/contract/base.py
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 284 285 286 287 288 289 290 291 292 293 294 |
|
DataStreamCollection ¶
DataStreamCollection(
name: str,
data_streams: List[DataStream],
*,
description: Optional[str] = None,
)
Bases: DataStreamCollectionBase[DataStream, UnsetParamsType]
Collection of data streams with direct initialization.
A specialized collection where child streams are passed directly instead of being created by a reader function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name identifier for the collection. |
required |
data_streams
|
List[DataStream]
|
List of child data streams to include. |
required |
description
|
Optional[str]
|
Optional description of the collection. |
None
|
Examples:
from contraqctor.contract import csv, text, DataStreamCollection
# Create streams
text_stream = text.Text("readme", reader_params=text.TextParams(path="README.md"))
csv_stream = csv.Csv("data", reader_params=csv.CsvParams(path="data.csv"))
# Create the collection
collection = DataStreamCollection("project_files", [text_stream, csv_stream])
# Load and use
collection.load_all()
readme_content = collection["readme"].data
Initializes a special DataStreamGroup where the data streams are passed directly, without a reader.
Source code in src/contraqctor/contract/base.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
name
property
¶
name: str
Get the name of the data stream.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Name identifier of the data stream. |
resolved_name
property
¶
resolved_name: str
Get the full hierarchical name of the data stream.
Generates a path-like name showing the stream's position in the hierarchy, using '::' as a separator between parent and child names.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The fully resolved name including all parent names. |
description
property
¶
parent
property
¶
parent: Optional[DataStream]
Get the parent data stream.
Returns:
Type | Description |
---|---|
Optional[DataStream]
|
Optional[DataStream]: Parent data stream, or None if this is a root stream. |
is_collection
property
¶
is_collection: bool
Check if this data stream is a collection of other streams.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if this is a collection stream, False otherwise. |
reader_params
property
¶
reader_params: TReaderParams
Get the parameters for the data reader.
Returns:
Name | Type | Description |
---|---|---|
TReaderParams |
TReaderParams
|
Parameters for the data reader. |
has_data
property
¶
has_data: bool
Check if the data stream has loaded data.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if data has been loaded, False otherwise. |
data
property
¶
data: TData
Get the loaded data.
Returns:
Name | Type | Description |
---|---|---|
TData |
TData
|
The loaded data. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
parameters
staticmethod
¶
parameters(*args, **kwargs) -> UnsetParamsType
Parameters function to return UnsetParams.
Returns:
Name | Type | Description |
---|---|---|
UnsetParamsType |
UnsetParamsType
|
Special unset parameters value. |
Source code in src/contraqctor/contract/base.py
495 496 497 498 499 500 501 502 |
|
read ¶
read(*args, **kwargs) -> List[DataStream]
Read data from the collection.
Returns:
Type | Description |
---|---|
List[DataStream]
|
List[DataStream]: The pre-set data streams. |
Raises:
Type | Description |
---|---|
ValueError
|
If data streams have not been set yet. |
Source code in src/contraqctor/contract/base.py
512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
bind_data_streams ¶
bind_data_streams(data_streams: List[DataStream]) -> Self
Bind a list of data streams to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_streams
|
List[DataStream]
|
List of data streams to include in the collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If data streams have already been set. |
Source code in src/contraqctor/contract/base.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
add_stream ¶
add_stream(stream: DataStream) -> Self
Add a new data stream to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
DataStream
|
Data stream to add to the collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
KeyError
|
If a stream with the same name already exists. |
Examples:
from contraqctor.contract import json, DataStreamCollection
# Create an empty collection
collection = DataStreamCollection("api_data", [])
# Add streams
collection.add_stream(
json.Json("config", reader_params=json.JsonParams(path="config.json"))
)
# Load the data
collection.load_all()
Source code in src/contraqctor/contract/base.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
remove_stream ¶
remove_stream(name: str) -> None
Remove a data stream from the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the data stream to remove. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If data streams have not been set yet. |
KeyError
|
If no stream with the given name exists. |
Source code in src/contraqctor/contract/base.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
|
from_data_stream
classmethod
¶
from_data_stream(data_stream: DataStream) -> Self
Create a DataStreamCollection from a DataStream object.
Factory method to convert a single data stream or collection into a DataStreamCollection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_stream
|
DataStream
|
Source data stream to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataStreamCollection |
Self
|
New collection containing the source stream's data. |
Raises:
Type | Description |
---|---|
TypeError
|
If the source is not a DataStream. |
ValueError
|
If the source has not been loaded yet. |
Source code in src/contraqctor/contract/base.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
bind_reader_params ¶
bind_reader_params(params: TReaderParams) -> Self
Bind reader parameters to the data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
TReaderParams
|
Parameters to bind to the data stream's reader. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The data stream instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If reader parameters have already been set. |
Source code in src/contraqctor/contract/base.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
at ¶
at(name: str) -> TDataStream
Get a child data stream by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the child data stream to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
TDataStream |
TDataStream
|
The child data stream with the given name. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
KeyError
|
If no child stream with the given name exists. |
Source code in src/contraqctor/contract/base.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
load ¶
load()
Load data for this collection.
Overrides the base method to add validation that loaded data is a list of DataStreams.
Returns:
Name | Type | Description |
---|---|---|
Self |
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If loaded data is not a list of DataStreams. |
Source code in src/contraqctor/contract/base.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
load_all ¶
load_all(
strict: bool = False,
) -> list[tuple[DataStream, Exception], None, None]
Recursively load this data stream and all child streams.
Performs depth-first traversal to load all streams in the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strict
|
bool
|
If True, raises exceptions immediately; otherwise collects and returns them. |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[tuple[DataStream, Exception], None, None]
|
List of tuples containing streams and exceptions that occurred during loading. |
Raises:
Type | Description |
---|---|
Exception
|
If strict is True and an exception occurs during loading. |
Examples:
# Load all streams and handle errors
errors = collection.load_all(strict=False)
if errors:
for stream, error in errors:
print(f"Error loading {stream.name}: {error}")
Source code in src/contraqctor/contract/base.py
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 284 285 286 287 288 289 290 291 292 293 294 |
|
iter_all ¶
iter_all() -> Generator[DataStream, None, None]
Iterator for all child data streams, including nested collections.
Implements a depth-first traversal of the stream hierarchy.
Yields:
Name | Type | Description |
---|---|---|
DataStream |
DataStream
|
All recursively yielded child data streams. |
Source code in src/contraqctor/contract/base.py
436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
Dataset ¶
Dataset(
name: str,
data_streams: List[DataStream],
*,
version: str | Version = "0.0.0",
description: Optional[str] = None,
)
Bases: DataStreamCollection
A version-tracked collection of data streams.
Extends DataStreamCollection by adding semantic versioning support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name identifier for the dataset. |
required |
data_streams
|
List[DataStream]
|
List of data streams to include in the dataset. |
required |
version
|
str | Version
|
Semantic version string or Version object. Defaults to "0.0.0". |
'0.0.0'
|
description
|
Optional[str]
|
Optional description of the dataset. |
None
|
Examples:
from contraqctor.contract import text, csv, Dataset
# Create streams
text_stream = text.Text("notes", reader_params=text.TextParams(path="notes.txt"))
csv_stream = csv.Csv("data", reader_params=csv.CsvParams(path="data.csv"))
# Create a versioned dataset
dataset = Dataset(
"experiment_results",
[text_stream, csv_stream],
version="1.2.3"
)
# Load the dataset
dataset.load_all(strict=True)
# Access streams
txt = dataset["notes"].data
csv_data = dataset["data"].data
print(f"Dataset version: {dataset.version}")
Initializes a Dataset with a version and a list of data streams.
Source code in src/contraqctor/contract/base.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
|
version
property
¶
version: Version
Get the semantic version of the dataset.
Returns:
Name | Type | Description |
---|---|---|
Version |
Version
|
Semantic version object. |
name
property
¶
name: str
Get the name of the data stream.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Name identifier of the data stream. |
resolved_name
property
¶
resolved_name: str
Get the full hierarchical name of the data stream.
Generates a path-like name showing the stream's position in the hierarchy, using '::' as a separator between parent and child names.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The fully resolved name including all parent names. |
description
property
¶
parent
property
¶
parent: Optional[DataStream]
Get the parent data stream.
Returns:
Type | Description |
---|---|
Optional[DataStream]
|
Optional[DataStream]: Parent data stream, or None if this is a root stream. |
is_collection
property
¶
is_collection: bool
Check if this data stream is a collection of other streams.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if this is a collection stream, False otherwise. |
reader_params
property
¶
reader_params: TReaderParams
Get the parameters for the data reader.
Returns:
Name | Type | Description |
---|---|---|
TReaderParams |
TReaderParams
|
Parameters for the data reader. |
has_data
property
¶
has_data: bool
Check if the data stream has loaded data.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if data has been loaded, False otherwise. |
data
property
¶
data: TData
Get the loaded data.
Returns:
Name | Type | Description |
---|---|---|
TData |
TData
|
The loaded data. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
read ¶
read(*args, **kwargs) -> List[DataStream]
Read data from the collection.
Returns:
Type | Description |
---|---|
List[DataStream]
|
List[DataStream]: The pre-set data streams. |
Raises:
Type | Description |
---|---|
ValueError
|
If data streams have not been set yet. |
Source code in src/contraqctor/contract/base.py
512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
bind_reader_params ¶
bind_reader_params(params: TReaderParams) -> Self
Bind reader parameters to the data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
TReaderParams
|
Parameters to bind to the data stream's reader. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The data stream instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If reader parameters have already been set. |
Source code in src/contraqctor/contract/base.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
at ¶
at(name: str) -> TDataStream
Get a child data stream by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the child data stream to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
TDataStream |
TDataStream
|
The child data stream with the given name. |
Raises:
Type | Description |
---|---|
ValueError
|
If data has not been loaded yet. |
KeyError
|
If no child stream with the given name exists. |
Source code in src/contraqctor/contract/base.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
load ¶
load()
Load data for this collection.
Overrides the base method to add validation that loaded data is a list of DataStreams.
Returns:
Name | Type | Description |
---|---|---|
Self |
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If loaded data is not a list of DataStreams. |
Source code in src/contraqctor/contract/base.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
load_all ¶
load_all(
strict: bool = False,
) -> list[tuple[DataStream, Exception], None, None]
Recursively load this data stream and all child streams.
Performs depth-first traversal to load all streams in the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strict
|
bool
|
If True, raises exceptions immediately; otherwise collects and returns them. |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[tuple[DataStream, Exception], None, None]
|
List of tuples containing streams and exceptions that occurred during loading. |
Raises:
Type | Description |
---|---|
Exception
|
If strict is True and an exception occurs during loading. |
Examples:
# Load all streams and handle errors
errors = collection.load_all(strict=False)
if errors:
for stream, error in errors:
print(f"Error loading {stream.name}: {error}")
Source code in src/contraqctor/contract/base.py
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 284 285 286 287 288 289 290 291 292 293 294 |
|
iter_all ¶
iter_all() -> Generator[DataStream, None, None]
Iterator for all child data streams, including nested collections.
Implements a depth-first traversal of the stream hierarchy.
Yields:
Name | Type | Description |
---|---|---|
DataStream |
DataStream
|
All recursively yielded child data streams. |
Source code in src/contraqctor/contract/base.py
436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
parameters
staticmethod
¶
parameters(*args, **kwargs) -> UnsetParamsType
Parameters function to return UnsetParams.
Returns:
Name | Type | Description |
---|---|---|
UnsetParamsType |
UnsetParamsType
|
Special unset parameters value. |
Source code in src/contraqctor/contract/base.py
495 496 497 498 499 500 501 502 |
|
bind_data_streams ¶
bind_data_streams(data_streams: List[DataStream]) -> Self
Bind a list of data streams to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_streams
|
List[DataStream]
|
List of data streams to include in the collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If data streams have already been set. |
Source code in src/contraqctor/contract/base.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
add_stream ¶
add_stream(stream: DataStream) -> Self
Add a new data stream to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
DataStream
|
Data stream to add to the collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The collection instance for method chaining. |
Raises:
Type | Description |
---|---|
KeyError
|
If a stream with the same name already exists. |
Examples:
from contraqctor.contract import json, DataStreamCollection
# Create an empty collection
collection = DataStreamCollection("api_data", [])
# Add streams
collection.add_stream(
json.Json("config", reader_params=json.JsonParams(path="config.json"))
)
# Load the data
collection.load_all()
Source code in src/contraqctor/contract/base.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
remove_stream ¶
remove_stream(name: str) -> None
Remove a data stream from the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the data stream to remove. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If data streams have not been set yet. |
KeyError
|
If no stream with the given name exists. |
Source code in src/contraqctor/contract/base.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
|
from_data_stream
classmethod
¶
from_data_stream(data_stream: DataStream) -> Self
Create a DataStreamCollection from a DataStream object.
Factory method to convert a single data stream or collection into a DataStreamCollection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_stream
|
DataStream
|
Source data stream to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataStreamCollection |
Self
|
New collection containing the source stream's data. |
Raises:
Type | Description |
---|---|
TypeError
|
If the source is not a DataStream. |
ValueError
|
If the source has not been loaded yet. |
Source code in src/contraqctor/contract/base.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|