Read the file as a BytesIO stream. To convert to a TextIO stream, wrap with io.TextIOWrapper. Note that by default the underlying stream won't be closed until fully consumed – it is strongly recommended to make the request within a with statement to ensure it’s always closed.




from io import TextIOWrapper

f = redivis.file("rnwk-acs3famee.pVr4Gzq54L3S9pblMZTs5Q")

with as f_stream: # read 100 bytes

with TextIOWrapper( as f_stream:
  f_stream.readline() # read first line
# We can use streams to work with files similarly 
# to if they were on disk, e.g.:  

from PIL import Image
# References the file bogota.tiff at
file = redivis.file("4c10-d8rqhswh8.zz7AB9NJB2ctNpDGKbRD7w")
# Pass the file as a bytesIO stream to PIL to load as an image

Last updated