> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# artifacts

# `prefect.server.models.artifacts`

## Functions

### `emit_artifact_collection_created_event` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L19](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L19)</sup>

```python theme={null}
emit_artifact_collection_created_event(artifact_collection: orm_models.ArtifactCollection) -> None
```

Emit an event when an artifact collection is created.

### `emit_artifact_collection_updated_event` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L29](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L29)</sup>

```python theme={null}
emit_artifact_collection_updated_event(artifact_collection: orm_models.ArtifactCollection) -> None
```

Emit an event when an artifact collection's latest artifact changes.

### `emit_artifact_collection_deleted_event` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L39](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L39)</sup>

```python theme={null}
emit_artifact_collection_deleted_event(artifact_collection: orm_models.ArtifactCollection) -> None
```

Emit an event when an artifact collection is deleted.

### `create_artifact` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L136](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L136)</sup>

```python theme={null}
create_artifact(session: AsyncSession, artifact: Artifact) -> orm_models.Artifact
```

### `read_latest_artifact` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L157](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L157)</sup>

```python theme={null}
read_latest_artifact(db: PrefectDBInterface, session: AsyncSession, key: str) -> Union[orm_models.ArtifactCollection, None]
```

Reads the latest artifact by key.
Args:
session: A database session
key: The artifact key
Returns:
Artifact: The latest artifact

### `read_artifact` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L178](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L178)</sup>

```python theme={null}
read_artifact(db: PrefectDBInterface, session: AsyncSession, artifact_id: UUID) -> Union[orm_models.Artifact, None]
```

Reads an artifact by id.

### `read_artifacts` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L288](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L288)</sup>

```python theme={null}
read_artifacts(db: PrefectDBInterface, session: AsyncSession, offset: Optional[int] = None, limit: Optional[int] = None, artifact_filter: Optional[filters.ArtifactFilter] = None, flow_run_filter: Optional[filters.FlowRunFilter] = None, task_run_filter: Optional[filters.TaskRunFilter] = None, deployment_filter: Optional[filters.DeploymentFilter] = None, flow_filter: Optional[filters.FlowFilter] = None, sort: sorting.ArtifactSort = sorting.ArtifactSort.ID_DESC) -> Sequence[orm_models.Artifact]
```

Reads artifacts.

**Args:**

* `session`: A database session
* `offset`: Query offset
* `limit`: Query limit
* `artifact_filter`: Only select artifacts matching this filter
* `flow_run_filter`: Only select artifacts whose flow runs matching this filter
* `task_run_filter`: Only select artifacts whose task runs matching this filter
* `deployment_filter`: Only select artifacts whose flow runs belong to deployments matching this filter
* `flow_filter`: Only select artifacts whose flow runs belong to flows matching this filter

### `read_latest_artifacts` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L335](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L335)</sup>

```python theme={null}
read_latest_artifacts(db: PrefectDBInterface, session: AsyncSession, offset: Optional[int] = None, limit: Optional[int] = None, artifact_filter: Optional[filters.ArtifactCollectionFilter] = None, flow_run_filter: Optional[filters.FlowRunFilter] = None, task_run_filter: Optional[filters.TaskRunFilter] = None, deployment_filter: Optional[filters.DeploymentFilter] = None, flow_filter: Optional[filters.FlowFilter] = None, sort: sorting.ArtifactCollectionSort = sorting.ArtifactCollectionSort.ID_DESC) -> Sequence[orm_models.ArtifactCollection]
```

Reads artifacts.

**Args:**

* `session`: A database session
* `offset`: Query offset
* `limit`: Query limit
* `artifact_filter`: Only select artifacts matching this filter
* `flow_run_filter`: Only select artifacts whose flow runs matching this filter
* `task_run_filter`: Only select artifacts whose task runs matching this filter
* `deployment_filter`: Only select artifacts whose flow runs belong to deployments matching this filter
* `flow_filter`: Only select artifacts whose flow runs belong to flows matching this filter

### `count_artifacts` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L381](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L381)</sup>

```python theme={null}
count_artifacts(db: PrefectDBInterface, session: AsyncSession, artifact_filter: Optional[filters.ArtifactFilter] = None, flow_run_filter: Optional[filters.FlowRunFilter] = None, task_run_filter: Optional[filters.TaskRunFilter] = None, deployment_filter: Optional[filters.DeploymentFilter] = None, flow_filter: Optional[filters.FlowFilter] = None) -> int
```

Counts artifacts.
Args:
session: A database session
artifact\_filter: Only select artifacts matching this filter
flow\_run\_filter: Only select artifacts whose flow runs matching this filter
task\_run\_filter: Only select artifacts whose task runs matching this filter

### `count_latest_artifacts` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L415](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L415)</sup>

```python theme={null}
count_latest_artifacts(db: PrefectDBInterface, session: AsyncSession, artifact_filter: Optional[filters.ArtifactCollectionFilter] = None, flow_run_filter: Optional[filters.FlowRunFilter] = None, task_run_filter: Optional[filters.TaskRunFilter] = None, deployment_filter: Optional[filters.DeploymentFilter] = None, flow_filter: Optional[filters.FlowFilter] = None) -> int
```

Counts artifacts.
Args:
session: A database session
artifact\_filter: Only select artifacts matching this filter
flow\_run\_filter: Only select artifacts whose flow runs matching this filter
task\_run\_filter: Only select artifacts whose task runs matching this filter

### `update_artifact` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L449](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L449)</sup>

```python theme={null}
update_artifact(db: PrefectDBInterface, session: AsyncSession, artifact_id: UUID, artifact: actions.ArtifactUpdate) -> bool
```

Updates an artifact by id.

**Args:**

* `session`: A database session
* `artifact_id`: The artifact id to update
* `artifact`: An artifact model

**Returns:**

* True if the update was successful, False otherwise

### `delete_artifact` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L488](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L488)</sup>

```python theme={null}
delete_artifact(db: PrefectDBInterface, session: AsyncSession, artifact_id: UUID) -> bool
```

Deletes an artifact by id.

The ArtifactCollection table is used to track the latest version of an artifact
by key. If we are deleting the latest version of an artifact from the Artifact
table, we need to first update the latest version referenced in ArtifactCollection
so that it points to the next latest version of the artifact.

Example:
If we have the following artifacts in Artifact:

* key: "foo", id: 1, created: 2020-01-01
* key: "foo", id: 2, created: 2020-01-02
* key: "foo", id: 3, created: 2020-01-03

the ArtifactCollection table has the following entry:

* key: "foo", latest\_id: 3

If we delete the artifact with id 3, we need to update the latest version of the
artifact with key "foo" to be the artifact with id 2.

**Args:**

* `session`: A database session
* `artifact_id`: The artifact id to delete

**Returns:**

* True if the delete was successful, False otherwise
