---
title: artifacts
sidebarTitle: artifacts
---

# `prefect.server.models.artifacts`

## Functions

### `create_artifact` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L99" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
create_artifact(session: AsyncSession, artifact: Artifact) -> orm_models.Artifact
```

### `read_latest_artifact` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L120" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

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


Reads an artifact by id.


### `read_artifacts` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L251" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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
- `work_pool_filter`: Only select artifacts whose flow runs belong to work pools matching this filter


### `read_latest_artifacts` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L299" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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
- `work_pool_filter`: Only select artifacts whose flow runs belong to work pools matching this filter


### `count_artifacts` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L346" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L380" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L414" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/artifacts.py#L453" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
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

