Reading from a Package

The examples in this section use the following mock package:

import t4
p = (t4.Package()
.set("trades.parquet", "trades.parquet")
.set("symbols.yaml", "symbols.yaml")
.set("commodities/gold.csv", "gold.csv")
.set("commodities/silver.csv", "silver.csv")

Slicing through a package

Use dict key selection to slice into a package tree:

$ python
>>> p["trades.parquet"]
<<< PackageEntry("trades.parquet")
>>> p["commodities"]
<<< gold.csv

Slicing into a Package directory returns another Package rooted at that subdirectory. Slicing into a package entry returns an individual PackageEntry.

Downloading package data to disk

To download a subset of files from a package directory to a dest, use fetch:

# download a subfolder
# download a single file
# download everything

fetch will default to downloading the files to the current directory, but you can also specify an alternative path:


Downloading package data into memory

Alternatively, you can download data directly into memory:

$ python
>>> p["commodities"]["gold.csv"]()
<<< <pandas.DataFrame object at ...>

To apply a custom deserializer to your data, pass the function as a parameter to the function. For example, to load a yaml file using yaml.safe_load:

$ python
>>> p["symbols.yaml"](yaml.safe_load)
<<< {'gold': 'au', 'silver': 'ag'}

The deserializer should accept a byte stream as input.

Getting entry locations

You can get the path to a package entry or directory using get:

# returns /path/to/workdir/commodities/gold.csv
# returns /path/to/workdir/

Getting metadata

Metadata is available using the meta property.

# get entry metadata
# get directory metadata
# get package metadata