speasy.products.catalog module

catalog module

class speasy.products.catalog.Catalog(name: str, meta: dict | None = None, events: List[Event] | None = None)[source]

Bases: SpeasyProduct

The Catalog class allows to manipulate a goup of events like a simple Python list of Event plus some meta data.

Examples

>>> import speasy
>>> from speasy.products import Catalog, Event
>>> my_catalog = Catalog(name='MyCatalog', meta={'tags':['demo', 'docstrings']}, events=[])
>>> my_catalog.append(Event('2018-01-01', '2018-01-02', meta={'name':'My first event!'}))
>>> my_catalog += Event('2019-01-01', '2019-01-02', meta={'name':'My second event!'})
>>> for e in my_catalog:
...     print(e)
...
<Event: 2018-01-01T00:00:00+00:00 -> 2018-01-02T00:00:00+00:00 | {'name': 'My first event!'}>
<Event: 2019-01-01T00:00:00+00:00 -> 2019-01-02T00:00:00+00:00 | {'name': 'My second event!'}>
Attributes:
namestr

Catalog name

metadict

All additional Catalog meta data

Methods

append:

Append an Event or a list of Event to the end of the Catalog

pop:

Remove and return Event at index (default last)

append(events: Event) None[source]

Append an Event or a list of Event to the end of the Catalog.

Parameters:
eventsEvent or List[Event]
Raises:
TypeError

If events is neither an Event or a list of Event

See also

Catalog.pop
meta
name
pop(index: int = -1) Event[source]

Remove and return Event at index (default last).

Parameters:
indexint
Returns:
Event

The removed event

Raises:
IndexError

if list is empty or index is out of range.

to_dataframe() DataFrame[source]
class speasy.products.catalog.Event(start_time: datetime, stop_time: datetime, meta=None)[source]

Bases: DateTimeRange

The Event class is a DatetimeRange with some meta data. It is supposed to be used with Catalog

Notes

This class support the same operations as a speasy.common.datetime_range.DateTimeRange.

Attributes:
start_timedatetime.datetime
stop_timedatetime.datetime
metadict

Additional event data

Methods

meta