annotools.io¶
Every source goes through fsspec, so a local path, an
s3:// URL and an https:// URL behave the same. Remote protocols need the matching backend from
annotools[remote].
io ¶
Reading and writing media through fsspec so local paths and remote URLs behave the same.
open_bytes ¶
Read the full content of a local path or fsspec URL.
Every source goes through fsspec so s3://, gs://, https:// and plain paths behave the
same; remote protocols need the matching backend from annotools[remote].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Local path or fsspec URL. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The raw bytes of the object. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When the URI does not exist; the message names the URI. |
OSError
|
For any other read failure (permissions, directory, unknown protocol, missing fsspec
backend such as |
Examples:
Source code in src/annotools/io.py
write_bytes ¶
Write bytes to a local path or fsspec URL, creating parent directories for local paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Destination path or fsspec URL. |
required |
data
|
bytes
|
Bytes to write (an encoded preview, a WAV clip). |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
Naming the target URI when it cannot be written. |
Examples:
Source code in src/annotools/io.py
load_image ¶
Decode an image from uri with EXIF orientation applied.
Applying the orientation here means every later coordinate refers to the image as a viewer (and an MLLM) sees it, not to the sensor layout stored in the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Local path or fsspec URL of an image Pillow can decode. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The decoded, orientation-corrected PIL image (mode as stored: RGB, RGBA, L, P, ...). |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When the URI does not exist (from |
OSError
|
For other read failures (from |
ValueError
|
When the content is not a decodable image (unknown format, truncated or corrupt data); the message names the URI. |
Examples: