DataEvent
laktory.models.DataEvent
¤
Bases: BaseModel
Data Event class defines both the context (metadata) describing a data event and its content. It is generally used to write data to a storage location.
ATTRIBUTE | DESCRIPTION |
---|---|
data |
Event data stored as a (key, value) object |
description |
Data event description |
event_root |
Root path for specific event. Default value:
TYPE:
|
events_root |
Root path for all events. Default value:
TYPE:
|
name |
Data event name
TYPE:
|
producer |
Data event producer
TYPE:
|
tstamp_col |
Column storing event UTC timestamp
TYPE:
|
tstamp_in_path |
If
TYPE:
|
Examples:
This is example one
from laktory import models
from datetime import datetime
event = models.DataEvent(
name="stock_price",
producer={"name": "yahoo-finance"},
)
print(event)
'''
variables={} data=None description=None events_root_=None event_root_=None name='stock_price' producer=DataProducer(variables={}, name='yahoo-finance', description=None, party=1) tstamp_col='created_at' tstamp_in_path=True
'''
print(event.event_root)
# > /Volumes/dev/sources/landing/events/yahoo-finance/stock_price/
event = models.DataEvent(
name="stock_price",
producer={"name": "yahoo-finance"},
data={
"created_at": datetime(2023, 8, 23),
"symbol": "GOOGL",
"open": 130.25,
"close": 132.33,
},
)
print(event)
'''
variables={} data={'created_at': datetime.datetime(2023, 8, 23, 0, 0), 'symbol': 'GOOGL', 'open': 130.25, 'close': 132.33, '_name': 'stock_price', '_producer_name': 'yahoo-finance', '_created_at': datetime.datetime(2023, 8, 23, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC'))} description=None events_root_=None event_root_=None name='stock_price' producer=DataProducer(variables={}, name='yahoo-finance', description=None, party=1) tstamp_col='created_at' tstamp_in_path=True
'''
print(event.dirpath)
# > /Volumes/dev/sources/landing/events/yahoo-finance/stock_price/2023/08/23/
print(event.get_landing_filepath())
'''
/Volumes/dev/sources/landing/events/yahoo-finance/stock_price/2023/08/23/stock_price_20230823T000000000Z.json
'''
print(event.get_storage_filepath())
# > /events/yahoo-finance/stock_price/2023/08/23/stock_price_20230823T000000000Z.json
METHOD | DESCRIPTION |
---|---|
get_filename |
Get file name associated with the data of the even, given a format |
get_landing_filepath |
Get file path on the landing mount/volume associated with the data of |
get_storage_filepath |
Get file path on the landing storage associated with the data of the |
to_path |
Write data event to local file path, given a format |
to_azure_storage_container |
Write data event to azure storage container, given a format |
to_aws_s3_bucket |
Write data event to azure storage container, given a format |
to_databricks |
Write data event to Databricks volume or mount, given a format |
ATTRIBUTE | DESCRIPTION |
---|---|
created_at |
Timestamp at which event was created.
TYPE:
|
events_root |
Must be computed to dynamically account for settings (env variable at run time)
TYPE:
|
event_root |
Root path for the event. Default path is
TYPE:
|
dirpath |
Path of the directory storing the event data.
TYPE:
|
Attributes¤
events_root
property
¤
events_root
Must be computed to dynamically account for settings (env variable at run time)
event_root
property
¤
event_root
Root path for the event. Default path is {self.events_roots}/{producer_name}/{event_name}/
, but it may
be overwritten by self.event_root_.
RETURNS | DESCRIPTION |
---|---|
str
|
Event path |
Functions¤
get_filename
¤
get_filename(fmt='json', suffix=None)
Get file name associated with the data of the even, given a format fmt
and a suffix
.
PARAMETER | DESCRIPTION |
---|---|
fmt
|
File format
TYPE:
|
suffix
|
File path suffix
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Data file path |
Source code in laktory/models/dataevent.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
get_landing_filepath
¤
get_landing_filepath(fmt='json', suffix=None)
Get file path on the landing mount/volume associated with the data of
the event, given a format fmt
and a suffix
.
PARAMETER | DESCRIPTION |
---|---|
fmt
|
File format
DEFAULT:
|
suffix
|
File path suffix
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Data file path |
Source code in laktory/models/dataevent.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
get_storage_filepath
¤
get_storage_filepath(fmt='json', suffix=None)
Get file path on the landing storage associated with the data of the
event, given a format fmt
and a suffix
.
PARAMETER | DESCRIPTION |
---|---|
fmt
|
File format
DEFAULT:
|
suffix
|
File path suffix
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Data file path |
Source code in laktory/models/dataevent.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
to_path
¤
to_path(suffix=None, fmt='json', overwrite=False, skip_if_exists=False)
Write data event to local file path, given a format fmt
and a
suffix
.
PARAMETER | DESCRIPTION |
---|---|
suffix
|
File path suffix
TYPE:
|
fmt
|
File format
TYPE:
|
overwrite
|
Overwrite file if already exists
TYPE:
|
skip_if_exists
|
If
TYPE:
|
Source code in laktory/models/dataevent.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
to_azure_storage_container
¤
to_azure_storage_container(suffix=None, fmt='json', container_client=None, account_url=None, container_name='landing', overwrite=False, skip_if_exists=False)
Write data event to azure storage container, given a format fmt
and a
suffix
.
PARAMETER | DESCRIPTION |
---|---|
suffix
|
File path suffix
TYPE:
|
fmt
|
File format
TYPE:
|
container_client
|
Authorized Azure container client
TYPE:
|
account_url
|
URL of storage account
TYPE:
|
container_name
|
Name of the storage container
TYPE:
|
overwrite
|
Overwrite file if already exists
TYPE:
|
skip_if_exists
|
If
TYPE:
|
Source code in laktory/models/dataevent.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
to_aws_s3_bucket
¤
to_aws_s3_bucket(bucket_name, suffix=None, fmt='json', s3_resource=None, overwrite=False, skip_if_exists=False)
Write data event to azure storage container, given a format fmt
and a
suffix
.
PARAMETER | DESCRIPTION |
---|---|
suffix
|
File path suffix
TYPE:
|
fmt
|
File format
TYPE:
|
s3_resource
|
Authorized S3 bucket resource
TYPE:
|
overwrite
|
Overwrite file if already exists
TYPE:
|
skip_if_exists
|
If
TYPE:
|
Source code in laktory/models/dataevent.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
|
to_databricks
¤
to_databricks(suffix=None, fmt='json', overwrite=False, skip_if_exists=False, storage_type='VOLUME')
Write data event to Databricks volume or mount, given a format fmt
and a suffix
.
PARAMETER | DESCRIPTION |
---|---|
suffix
|
File path suffix
TYPE:
|
fmt
|
File format
TYPE:
|
overwrite
|
Overwrite file if already exists
TYPE:
|
skip_if_exists
|
If
TYPE:
|
storage_type
|
Specify if data is written to a mount or a volume.
TYPE:
|
Source code in laktory/models/dataevent.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|