---
title: "Get Revisions"
url: "https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading"
version: "6.2"
language: "python"
---

# Get Revisions

> Client language: Python. Also available for [C#](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.md), [Java](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.java.md), [PHP](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.php.md), [Node.js](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/loading.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - Using the Advanced Session methods you can **retrieve revisions and their metadata**  
>   from the database for the specified document.
>
> - These methods can also be executed lazily, see [get revisions lazily](https://docs.ravendb.net/6.2/client-api/session/how-to/perform-operations-lazily.python.md#getrevisions).
>
> - In this page:
>   - [Get all revisions](#get-all-revisions)
>   - [Get revisions metadata](#get-revisions-metadata)
>   - [Get revisions by creation time](#get-revisions-by-creation-time)
>   - [Get revisions by change vector](#get-revisions-by-change-vector)

## Get all revisions

Use `get_for` to retrieve all of the revisions currently kept for the specified document.

- **Example**:

```python
# Get revisions for document 'orders/1-A'
# Revisions will be ordered by most recent revision first
order_revisions = session.advanced.revisions.get_for("orders/1-A", Order, 0, 10)
```

- **Syntax**:

```python
def get_for(self, id_: str, object_type: Type[_T] = None, start: int = 0, page_size: int = 25) -> List[_T]: ...
```

| Parameters | Type | Description |
| - | - | - |
| **id\_** | `str` | Document ID for which to retrieve revisions |
| **object\_type** | `Type[_T]` | The type of the object whose revisions we want to retrieve |
| **start** | `int` | First revision to retrieve, used for paging |
| **page\_size** | `int` | Number of revisions to retrieve per results page |

## Get revisions metadata

Use `get_metadata_for` to retrieve the metadata for all the revisions currently kept for the specified document.

- **Example**:

```python
# Get 'revisions' metadata for document 'orders/1-A'
order_revisions_metadata = session.advanced.revisions.get_metadata_for("orders/1-A", 0, 10)

# Each item returned is a revision's metadata, as can be verified in the @flags key
metadata = order_revisions_metadata[0]
flags_value = metadata[constants.Documents.Metadata.FLAGS]

self.assertIn("Revision", flags_value)
```

- **Syntax**:

```python
def get_metadata_for(self, id_: str, start: int = 0, page_size: int = 25) -> List["MetadataAsDictionary"]: ...
```

| Parameters | Type | Description |
| - | - | - |
| **id\_** | `str` | Document ID for which to retrieve revisions' metadata |
| **start** | `int` | First revision to retrieve metadata for, used for paging |
| **page\_size** | `int` | Number of revisions to retrieve per results page |

## Get revisions by creation time

Use `get_by_before_date` to retrieve a revision by its **creation time**.

- **Example**:

```python
# Get a revision by its creation time
revision_from_last_year = (
  session.advanced.revisions
  # If no revision was created at the specified time,
  # then the first revision that precedes it will be returned
  .get_by_before_date("orders/1-A", datetime.datetime.utcnow() - datetime.timedelta(days=365))
)
```

- **Syntax**:

```python
def get_by_before_date(self, id_: str, before_date: datetime.datetime, object_type: Type[_T] = None) -> _T: ...
```

| Parameter | Type | Description |
| - | - | - |
| **id\_** | `str` | The ID of the document whose revisions we want to retrieve by creation time |
| **before\_date** | `datetime.datetime` | Revision creation time |
| **object\_type** | `Type[_T]` | The type of the object whose revisions we want to retrieve |

## Get revisions by change vector

To retrieve a revision or multiple revisions by **change vectors**, get the
change vector using `get_metadata_for` and the revisions using `get_by_change_vector`.

- **Example**:

```python
# Get revisions metadata
revisions_metadata = session.advanced.revisions.get_metadata_for("orders/1-A", 0, 25)

# Get the change-vector from the metadata
change_vector = revisions_metadata[0][constants.Documents.Metadata.CHANGE_VECTOR]

# Get the revision by its change-vector
revision = session.advanced.revisions.get_by_change_vector(change_vector, Order)
```

- **Syntax**:

```python
# Get a revision by its change vector
def get_by_change_vector(self, change_vector: str, object_type: Type[_T] = None) -> _T: ...

# Get multiple revisions by their change vectors
def get_by_change_vectors(self, change_vectors: List[str], object_type: Type[_T] = None) -> Dict[str, _T]: ...
```

| Parameter | Type | Description |
| - | - | - |
| **change\_vectors** | `List[str]` | A list of change vector strings |
| **object\_type** | `Type[_T]` | The types of the objects whose revisions we want to retrieve |

## See also

- [Document Revisions Overview](https://docs.ravendb.net/6.2/document-extensions/revisions/overview.python.md)
- [Revert Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/revert-documents-to-revisions/revert-documents-to-specific-time.md)
- [Revisions and Other Features](https://docs.ravendb.net/6.2/document-extensions/revisions/revisions-and-other-features.python.md)
- [Revisions: API Overview](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/overview.python.md)
- [Operations: Configuring Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/operations/configure-revisions.python.md)
- [Session: Including Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/including.md)
- [Session: Counting Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/session/counting.python.md)
- [Settings: Document Revisions](https://docs.ravendb.net/6.2/studio/database/settings/document-revisions.md)
- [Document Extensions: Revisions](https://docs.ravendb.net/6.2/studio/database/settings/document-revisions.md)
