Skip to content

Sample

Interface for Sample objects.

Sample

Sample(inner: SampleTable)

Interface to a dataset sample.

It is usually returned by a query to the dataset.

for sample in dataset:
    ...

Many properties of the sample are directly accessible as attributes of this class.

print(f"Sample file name: {sample.file_name}")
print(f"Sample file path: {sample.file_path_abs}")
print(f"Sample width: {sample.width}")
print(f"Sample height: {sample.height}")
Note that some attributes like the sample_id are technically writable, but changing them is not recommended and may lead to inconsistent states.

Access sample's metadata via the metadata property, which provides a dictionary-like interface to get and set metadata key-value pairs.

some_value = sample.metadata["some_key"]
sample.metadata["another_key"] = "new_value"

Access sample's tags via the tags property.

sample.tags = ["tag1", "tag2"]  # Replace all tags
print(f"Current tags: {sample.tags}")
sample.add_tag("tag_3")
sample.remove_tag("tag_1")

Parameters:

Name Type Description Default
inner SampleTable

The SampleTable SQLAlchemy model instance.

required

metadata property

metadata: SampleMetadata

Get dictionary-like access to sample metadata.

Returns:

Type Description
SampleMetadata

A dictionary-like object for accessing metadata.

tags property writable

tags: set[str]

Get the tag names associated with this sample.

Returns:

Type Description
set[str]

A set of tag names as strings.

add_tag

add_tag(name: str) -> None

Add a tag to this sample.

If the tag doesn't exist, it will be created first.

Parameters:

Name Type Description Default
name str

The name of the tag to add.

required

get_object_session

get_object_session() -> Session

Get the database session for this sample.

Returns:

Type Description
Session

The SQLModel session.

Raises:

Type Description
RuntimeError

If no active session is found.

remove_tag

remove_tag(name: str) -> None

Remove a tag from this sample.

Parameters:

Name Type Description Default
name str

The name of the tag to remove.

required