Skip to content

File

file

Dealing with file infos of the Notion API.

FO_co = TypeVar('FO_co', bound=(objs.FileObject), default=(objs.FileObject), covariant=True) module-attribute

MAX_FILE_SIZE = 20000000 module-attribute

Maximum file size for single part upload. It's 5MB only for the free plan

NOTION_HOSTED_DOMAIN = 'secure.notion-static.com' module-attribute

AnyFile(*args: Any, **kwargs: Any)

Information about a web resource e.g. for the files property.

caption: Text | None property writable

Return the caption of the file.

name: str | None property writable

Return the name of the file.

__eq__(other: object) -> bool

__hash__() -> int

__str__() -> str abstractmethod

ExternalFile(*, url: str, name: str | None = None, caption: str | None = None)

Information about a file that is hosted externally, i.e. not by Notion.

url: str property

__repr__() -> str

__str__() -> str

NotionFile(*, url: str, name: str | None = None, caption: str | None = None)

Information about a file that is hosted by Notion.

url: str property

__repr__() -> str

__str__() -> str

UploadedFile(*args: Any, **kwargs: Any)

Information about a file that has been uploaded to Notion.

Note

This class is used to represent files that have been uploaded to Notion. After it has been used, e.g. to change a cover or add a file block, it will be converted to a NotionFile (i.e. objs.HostedFile), when read again from the API.

content_length: int | None property

Return the content length of the uploaded file.

content_type: str | None property

Return the content type of the uploaded file.

expiry_time: pnd.DateTime | None property

Return the expiry time of the uploaded file.

file_import_result: objs.FileImportSuccess | objs.FileImportError | None property

Return the file import result of the uploaded file.

file_name: str | None property

Return the file name of the uploaded file.

id: UUID property

Return the ID of the uploaded file.

obj_file_upload: objs.FileUpload instance-attribute

poll_interval: float = 1.0 class-attribute instance-attribute

status: FileUploadStatus property

Return the status of the uploaded file.

__repr__() -> str

__str__() -> str

from_file_upload(file_upload: objs.FileUpload) -> Self classmethod

Create an UploadedFile instance from a FileUpload object.

update_status() -> Self

Update the uploaded file information.

wait_until_uploaded() -> Self

Wait until the uploaded file is fully processed.

get_file_size(file: BinaryIO) -> int

Get the size of a file in bytes.

This function preserves the current file position.

Parameters:

Name Type Description Default
file BinaryIO

The binary file object to measure

required

Returns:

Type Description
int

The size of the file in bytes

get_mime_type(file: BinaryIO) -> str

Detect the MIME type of a file.

This function preserves the current file position.

Parameters:

Name Type Description Default
file BinaryIO

The binary file object to analyze

required

Returns:

Type Description
str

The detected MIME type, or 'application/octet-stream' if unknown

is_notion_hosted(url: str) -> bool

Check if the URL is hosted on Notion.

url(url: str, *, name: str | None = None, caption: str | None = None) -> NotionFile | ExternalFile

Create a NotionFile or ExternalFile based on the URL.

A name and caption can be provided and will be used as default values, e.g. in a File block.