ORIONIS API REFERENCE

THE ORIONIS API

Build with clarity.

Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.

class documentation

Hold an uploaded file in memory or spill it to a temporary file on disk.

Parameters
filenameOriginal name of the uploaded file as reported by the client.
content_typeMIME type declared by the client, or None if absent.
memory_thresholdMaximum in-memory bytes before spilling to disk (default 1 MiB).
Static Method _sanitizeFilename Return a safe version of filename suitable for use on the filesystem.
Method __del__ Release resources when the object is garbage collected.
Method __init__ Initialize a new UploadedFile for an incoming multipart part.
Method chunks Iterate over the file content in fixed-size chunks.
Method close Close the file handle and release all associated resources.
Method read Read the entire file content from the beginning.
Method replace Replace the file content with data and update the byte counter.
Method requiresDiskWrite Determine whether the next write spills to the backing disk file.
Method save Write the file contents to path on the local filesystem.
Method write Append chunk to the file buffer.
Class Variable __slots__ Undocumented
Instance Variable _extension Undocumented
Instance Variable _file Undocumented
Instance Variable _memory_threshold Undocumented
Instance Variable _rolled Undocumented
Instance Variable _size Undocumented
Instance Variable content_type Undocumented
Instance Variable filename Undocumented
Property extension Return the file extension derived from filename, in lowercase.
Property size Return the total number of bytes written so far.
def _sanitizeFilename(filename: str) -> str: (source)

Return a safe version of filename suitable for use on the filesystem.

Strips null bytes, control characters, path separators, and Windows-reserved characters. Removes leading dots to prevent dotfile or path-traversal attacks. Falls back to "upload" when the sanitized result is empty.

Parameters
filename:strRaw filename as supplied by the client.
Returns
strSanitized filename safe for local persistence.
def __del__(self): (source)

Release resources when the object is garbage collected.

Returns
NoneUndocumented
def __init__(self, filename: str, content_type: str | None, memory_threshold: int = 1024 * 1024): (source)

Initialize a new UploadedFile for an incoming multipart part.

The filename is sanitized on ingestion: control characters, path separators, and Windows-reserved characters are stripped, and path-traversal sequences (leading dots) are removed. If the result is empty after sanitization the filename falls back to "upload".

Parameters
filename:strOriginal name of the uploaded file as reported by the client.
content_type:str or NoneMIME type declared by the client, or None if absent.
memory_threshold:int, optionalMaximum in-memory bytes before spilling to disk (default 1 MiB).
Returns
NoneUndocumented
def chunks(self, size: int = _CHUNK_SIZE) -> Iterator[bytes]: (source)

Iterate over the file content in fixed-size chunks.

Rewinds the buffer and yields consecutive chunks so large uploads can be consumed without loading everything in memory.

Parameters
size:intMaximum number of bytes per yielded chunk.
Returns
Iterator[bytes]Undocumented
Yields
bytesConsecutive chunks from the beginning of the content.
def close(self): (source)

Close the file handle and release all associated resources.

SpooledTemporaryFile removes the backing temp file on close automatically, so no manual unlink is required.

Returns
NoneUndocumented
def read(self) -> bytes: (source)

Read the entire file content from the beginning.

Returns
bytesFull file contents.
def replace(self, data: bytes): (source)

Replace the file content with data and update the byte counter.

Used internally after Content-Transfer-Encoding decoding (base64 or quoted-printable) to write the decoded payload back into the spooled buffer.

Parameters
data:bytesNew file content that replaces whatever was previously written.
Returns
NoneUndocumented
def requiresDiskWrite(self, size: int = 0) -> bool: (source)

Determine whether the next write spills to the backing disk file.

Parameters
size:int, optionalNumber of bytes that would be written in the next chunk.
Returns
boolTrue when the buffer is already rolled over or the next write would exceed the in-memory threshold.
def save(self, path: str | Path): (source)

Write the file contents to path on the local filesystem.

Streams the data in _CHUNK_SIZE (64 KiB) chunks so that large uploads are never loaded entirely into memory.

Parameters
path:str or PathDestination path for the saved file.
Returns
NoneUndocumented
def write(self, chunk: bytes | bytearray | memoryview): (source)

Append chunk to the file buffer.

Seek to the end before writing, including after a partial read. SpooledTemporaryFile spills to a real temp file on disk automatically once memory_threshold bytes are exceeded.

Parameters
chunk:bytes | bytearray | memoryviewRaw bytes to append.
Returns
NoneUndocumented
_extension: str = (source)

Undocumented

Undocumented

_memory_threshold = (source)

Undocumented

Undocumented

Undocumented

content_type: str or None = (source)

Undocumented

filename: str = (source)

Undocumented

Return the file extension derived from filename, in lowercase.

Returns
strLowercase suffix including the leading dot (e.g. ".png"). Empty string if the filename has no extension.

Return the total number of bytes written so far.

Returns
intCumulative byte count across all write calls.