Skip to main content
The Bucket methods, their Python options and what they return. Each section links to the concept page with the behaviour and defaults.
app/blob.py
Building the client, and the async AsyncBucket, are on Overview. Every method below exists on both, with the same arguments; on AsyncBucket it is awaited. Options are keyword-only.

put

app/reports.py
Every option is optional. Behaviour and defaults are on Writing. The result is a CompletedBlob:

Bodies

PutBody is one of these. If the body does not carry its own length or type, declare size or content_type yourself. An explicit content_type wins over a guess.
  • A str body is the text itself, never a file name. Wrap a file name in Path(...).
  • A file object is not closed for you. A file opened in text mode, or an iterable that yields str, raises a TypeError. So does a body of any other type.
  • AsyncBucket reads a sync file object on a worker thread, so the event loop is never blocked on disk. An async file object, such as one from aiofiles, cannot report its length.
  • There is no request body type, so put never raises empty_body. An empty bytes stores a zero-byte object.

Framework uploads

app/main.py
A framework’s uploaded file is a file object, but a type guessed from its name is not reliable: FastAPI’s spooled file has no name, and on Flask name is the form field. Pass content_type from what the framework parsed: file.content_type on FastAPI’s UploadFile, f.mimetype on Flask’s request.files[...], f.content_type on Django’s request.FILES[...]. The bytes pass through your server here, under your platform’s body limit. For anything large, use an upload handler instead.

Iterables

An iterable with neither raises length_required. Why is on Streams and unknown lengths. One that ends short of size, or runs past it, raises invalid_input.
On AsyncBucket, an async iterable works the same way.

unique_path

Exported from upstash_blob. The suffix rules are on Unique paths.

update_json

fn gets the parsed document, or None, and returns what json.dumps can write. On Bucket it is a plain function. On AsyncBucket it may also be async def. The result is a CompletedBlob, with content_type set to application/json. The loop and its defaults are on Updating JSON.

copy and move

What carries over from the source is on copy and move.

signed_upload_url

Returns a SignedUploadUrl with url: str, headers: dict[str, str] and expires_at: datetime. Send headers verbatim. Defaults and lifetimes are on Signed upload URLs.

get

Unlike the TypeScript SDK, get reads the whole body into memory before it returns. content is bytes; text() decodes it, UTF-8 by default, and json() parses it:
A missing object raises not_found. It never returns None. See get.

stream

For an object too big to hold in memory, stream() is get with the body left on the wire. It is a context manager: the record is ready on entry, the bytes are read inside the block, and the connection is released on exit. A missing object raises not_found on entry. The BlobStream it yields has the same fields as BlobDownload, minus content, plus iter_bytes(chunk_size=None) and read(). On AsyncBucket it is an async context manager yielding an AsyncBlobStream:
AsyncBlobStream.read() is awaited.

info and exists

See info and exists.

list

Returns a ListPage with blobs: list[BlobObject] and cursor: str | None. Defaults and paging are on list.

public_url

None on a private bucket. An empty path, or one with a . or .. segment, raises a ValueError. On AsyncBucket it is awaited, because the first call fetches credentials. See Public URLs.

signed_read_url

Returns a SignedReadUrl with url: str and expires_at: datetime. Cache the link until expires_at, never until a deadline you compute from expires_in. Defaults and lifetimes are on Signed read URLs.

delete

del is a Python keyword, so the method is delete. Pass a path or a list positionally, or prefix=; both or neither raises invalid_input. A path with a . or .. segment raises a ValueError. What each shape does and raises is on Deleting.

Multipart cleanup

MultipartUpload is a dataclass with path: str, upload_id: str and initiated_at: datetime | None. initiated_at is None when storage sent a date that does not parse, and such an upload is never treated as stale. abort_multipart_upload takes the record, not two strings, because a swapped pair would abort nothing and report success. Anything else is refused with invalid_input. To abort an upload whose id you stored from an upload handler, build the record:
older_than is required. See Incomplete multipart uploads.

s3

Short-lived credentials for boto3 or any S3 client. See Using an S3 client.

Records

Records are frozen dataclasses. They nest. What each field means is on Records. All of them are exported from upstash_blob.