Python SDK (v0.28.0)Guides
Files
A guide on how to work with files using the WriftAI Python client
This section demonstrates common file operations you can perform with the WriftAI Python client. These examples are not exhaustive — check the client reference for all options.
Upload a file
The simplest way to upload is from a file path:
download_url = wriftai.files.upload(
Path("report.pdf"),
"prediction",
)You can also upload raw bytes. The name parameter is required in this case:
download_url = wriftai.files.upload(
b"raw file contents",
"prediction",
name="data.bin",
)File-like objects are supported as well. If the object has a name attribute,
it will be used automatically:
with open("chart.png", "rb") as f:
download_url = wriftai.files.upload(f, "prediction")To override the inferred file name (and therefore the MIME type), pass name explicitly:
download_url = wriftai.files.upload(
Path("output.tmp"),
"prediction",
name="results.csv",
)Generate file URLs
This is a low-level method — most callers should use upload instead. It returns
a pair of URLs for uploading and downloading a file:
urls = wriftai.files.create_urls({
"name": "scan.pdf",
"size": 102400,
"resource": "prediction",
"mime_type": "application/pdf",
})
urls["upload_url"] # PUT your file contents here
urls["download_url"] # use this to retrieve the file later