Working with non-tabular files

Load a single file

import redivis
from PIL import Image

# References the file bogota.tiff at https://redivis.com/datasets/yz1s-d09009dbb/files/4c10-d8rqhswh8.zz7AB9NJB2ctNpDGKbRD7w
file = redivis.file("4c10-d8rqhswh8.zz7AB9NJB2ctNpDGKbRD7w")
file.get() # file.properties is now populated

# Download the file
download_location = file.download("./my-downloads")
f = open(download_location, "r")

# Read the image file
file_content_bytes = file.read()
# Pass the file as a bytesIO stream to PIL to load as an image
print(Image.open(file.stream()))

# We can also work with text file data, e.g.:
file = redivis.file("4c10-bk27tqmet.rkgXgUlmnJrEFFC6oWAqqA")
file_content_string = file.read(as_text=True)
with TextIOWrapper(file.stream()) as f:
  f.readline() # read first line

Load all files in a table

import redivis

table = redivis.organization("Demo").dataset("example_data_files").table("example_file_types")

# Download all files
table.download_files("./table_files/")

# Read all files into memory — only do this for a few small files!
files = table.list_files()
file_content_bytes = [
    file.read()
    for file in files
]

Last updated