---
title: "Document Refresh: Client API"
description: "Enable and configure document refresh for a database using the client API, and schedule document refreshes by setting the @refresh metadata property."
url: "https://docs.ravendb.net/7.2/documents/document-refresh/client-api"
version: "7.2"
language: "python"
---

# Document Refresh: Client API

> Client language: Python. Also available for [C#](https://docs.ravendb.net/7.2/documents/document-refresh/client-api.md), [Java](https://docs.ravendb.net/7.2/documents/document-refresh/client-api.java.md), [PHP](https://docs.ravendb.net/7.2/documents/document-refresh/client-api.php.md), [Node.js](https://docs.ravendb.net/7.2/documents/document-refresh/client-api.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**
>
> - The **document refresh** feature re-saves an existing document once the time you schedule for it has passed,
>   without changing the document's data.  
>   Re-saving the document triggers features that react to document updates, like indexing, ETL tasks, and data
>   subscriptions.  
>   Use *document refresh* for documents that need to be processed at a later time, like documents that hold emails to send
>   on a set date, room reservations to release once they expire, or reminders to raise when they are due.
>
> - To schedule a document's refresh, set the `@refresh` [metadata](https://docs.ravendb.net/7.2/client-api/session/how-to/get-and-modify-entity-metadata.python.md)
>   property of the document to the intended refresh time.  
>   The `@refresh` property is removed when the document is re-saved.
>
> - To enable *document refresh* for a database, send the server a `RefreshConfiguration` object using the
>   [ConfigureRefreshOperation](#configurerefreshoperation) operation.  
>   The `RefreshConfiguration` object also sets the frequency at which the *document refresh* feature checks the database
>   for documents to refresh.
>
> - To enable and configure *document refresh* using Studio, see
>   [Document Refresh: Studio View](https://docs.ravendb.net/7.2/documents/document-refresh/document-refresh-view.md).
>
> - In this article:
>   - [Refreshing documents](#refreshing-documents)
>     - [The refresh process](#the-refresh-process)
>   - [Enabling document refresh](#enabling-document-refresh)
>   - [Scheduling a document refresh](#scheduling-a-document-refresh)
>   - [Syntax](#syntax)
>     - [ConfigureRefreshOperation](#configurerefreshoperation)
>     - [Classes](#classes)

## Refreshing documents {#refreshing-documents}

Using **document refresh**, you can schedule RavenDB to re-save a document at a set time.  
This way, features that react to document changes (e.g., indexes and ETL tasks) process the document once the set time has
passed, with no further action required from your application.

For example:

- An email that should be sent on a set date.
- A room reservation that should be released once it expires.
- A reminder that should be raised when it is due.

To have a document processed only once its refresh time has passed, make the subscription query, index definition, or ETL
script that handles the document skip documents whose metadata still holds the `@refresh` property.  
e.g., a data subscription with the query `from Emails as e where true and not exists(e.'@metadata'.'@refresh')` sends an
email document to its worker only after the document is refreshed.

---

### The refresh process

1. **Enabling document refresh for a database:**  
   *Document refresh* is **disabled** by default.
   See [Enabling document refresh](#enabling-document-refresh) below.

2. **Scheduling a document's refresh:**  
   Add a `@refresh` property to the
   [metadata](https://docs.ravendb.net/7.2/client-api/session/how-to/get-and-modify-entity-metadata.python.md) of the document you want to
   refresh, and set the property's value to the intended refresh time.  
   e.g., `"@refresh": "2026-12-01T08:00:00.0000000Z"`  
   See [Scheduling a document refresh](#scheduling-a-document-refresh) below.

3. **Refreshing the scheduled document:**  
   The *document refresh* feature runs periodically (every 60 seconds by default).  
   Each time the feature runs, it checks the database for documents to refresh.

   - In the feature's first run after a document's refresh time, the `@refresh` property is removed from the document's metadata,
     and the modified document is stored.  
     As a result, the document's [change vector](https://docs.ravendb.net/7.2/server/clustering/replication/change-vector.md) is incremented,
     indicating that the document was updated.
   - The document may be refreshed in a later run if the number of documents due for refresh exceeds the maximum set for
     a single run using the Studio option
     [Set max number of documents to process in a single run](https://docs.ravendb.net/7.2/documents/document-refresh/document-refresh-view.md#set-max-number-of-documents-to-process-in-a-single-run).

4. **Processing the refreshed document:**  
   Features that react to document changes are triggered by this update and process the refreshed document.  
   For example:

   - The document is re-indexed by the indexes defined for the document's collection.
   - The document is replicated to the other nodes of the
     [database group](https://docs.ravendb.net/7.2/server/clustering/distribution/distributed-database.md),
     and to the destinations of [external replication](https://docs.ravendb.net/7.2/server/ongoing-tasks/external-replication.md) tasks.
   - An [ETL task](https://docs.ravendb.net/7.2/server/ongoing-tasks/etl/basics.md) whose transformation script handles the document's collection
     runs the script over the document.
   - A [data subscription](https://docs.ravendb.net/7.2/data-subscriptions/overview.md) whose query matches the
     updated document sends the document to the subscription's worker (or to one of its workers, for a
     [concurrent subscription](https://docs.ravendb.net/7.2/data-subscriptions/concurrent-subscriptions.md)).
   - If [revisions](https://docs.ravendb.net/7.2/document-extensions/revisions/overview.python.md) are enabled for the document's collection, a new revision
     of the document is created.

5. **Rescheduling the document's refresh:**  
   Since the `@refresh` property is removed, the document is refreshed only once.  
   To refresh the document again, set the document's `@refresh` metadata property to a new time.

## Enabling document refresh {#enabling-document-refresh}

To enable *document refresh* for a database, send the server a
[RefreshConfiguration](#refreshconfiguration) object with its `disabled` property
set to `False`, using the
[ConfigureRefreshOperation](#configurerefreshoperation) operation.

e.g., the following code enables *document refresh* and sets the interval between checks to five minutes.

```python
# Define the refresh configuration
refresh_configuration = RefreshConfiguration(
    # Enable document refresh for the database
    disabled=False,
    # Check the database for documents to refresh every 5 minutes
    refresh_frequency_in_sec=300,
)

# Send the configuration to the server
store.maintenance.send(ConfigureRefreshOperation(refresh_configuration))
```

> **Note**
>
> On a **secure server**, enabling or configuring the *document refresh* feature requires, like other changes to a database's
> configuration, a client certificate with `Admin` access to the database (or with an `Operator` or `Cluster Admin`
> [security clearance](https://docs.ravendb.net/7.2/server/security/authorization/security-clearance-and-permissions.md)).  
> Setting a document's `@refresh` metadata property, on the other hand, is a change to the document, which `Read/Write` access
> permits.  
> See [Setting up Authentication and Authorization](https://docs.ravendb.net/7.2/client-api/setting-up-authentication-and-authorization.md)

The `RefreshConfiguration` object holds the following settings:

- #### `disabled`
  Set this property to `False` to enable *document refresh*, or to `True` to disable the feature.  
  The default value for this property is `None`, so set the property explicitly.

- #### `refresh_frequency_in_sec`
  Sets the interval, in seconds, between the *document refresh* feature's checks for documents to refresh.  
  The default value for this property is 60 seconds.
  - **The `refresh_frequency_in_sec` value must be greater than 0:**  
    Sending a value of 0 or less fails with a `RavenException`.  
    e.g., the following code sends a `refresh_frequency_in_sec` value of 0 and catches the resulting exception.

    ```python
    try:
        store.maintenance.send(
            ConfigureRefreshOperation(RefreshConfiguration(disabled=False, refresh_frequency_in_sec=0))
        )
    except RavenException as e:
        # The exception's message includes:
        # "Refresh frequency for database '<database name>' must be greater than 0."
        pass
    ```
  - **On a [Community license](https://ravendb.net/buy), the `refresh_frequency_in_sec` value must be at least 129600 (36 hours):**  
    Enabling *document refresh* with a lower value, or without setting `refresh_frequency_in_sec` (so that the 60-second default
    applies), fails with a `LicenseLimitException`.  
    e.g., the code at the beginning of this section, which sets `refresh_frequency_in_sec` to 300, fails on a Community license.

---

You can also enable *document refresh* when you create a database, by setting the `refresh` property of the database record
to a `RefreshConfiguration` object.

## Scheduling a document refresh {#scheduling-a-document-refresh}

To schedule a document's refresh, set the `@refresh` metadata property of the document to the intended refresh time, and save
the document.

> **Warning**
>
> The `@refresh` metadata property is reserved for the *document refresh* feature.  
> Do not use it for any other purpose: RavenDB reads any value set for this property as a refresh time.  
> A valid date and time schedules the document's refresh, and any other value makes saving the document fail.

e.g., the following code schedules a refresh of the `users/1-A` document for one hour from now.

```python
with store.open_session() as session:
    # Load the document
    user = session.load("users/1-A", User)

    # Set the document's refresh time to one hour from now, as a UTC string
    refresh_time = datetime.now(timezone.utc) + timedelta(hours=1)
    session.advanced.get_metadata_for(user)["@refresh"] = refresh_time.strftime("%Y-%m-%dT%H:%M:%S.%f0Z")

    # Save the document
    session.save_changes()
```

- #### Setting the refresh time in UTC

  Set the `@refresh` property to a string that holds a UTC time with a `Z` suffix, which marks the time as UTC, so the server
  reads the intended time correctly.  
  e.g., for a UTC `datetime` value, `refresh_time.strftime("%Y-%m-%dT%H:%M:%S.%f0Z")` returns a string like
  `"2026-12-01T08:00:00.0000000Z"`

  > **Note**
  >
  > Do not set the property to a `datetime` object, even a timezone-aware one (e.g., `datetime.now(timezone.utc) + timedelta(hours=1)`).  
  > If you set a `datetime` object, the client will send the value without a time zone designator, and the server will read the
  > value as the server machine's local time. If the client machine and the server machine are in different time zones, the
  > document will be refreshed at a different time than intended.

- #### Setting an invalid refresh time
  If the value of the `@refresh` property is not a valid date and time, `save_changes` raises a `RavenException`, and none
  of the session's changes are saved.

- #### Scheduling while *document refresh* is disabled
  Setting the `@refresh` property while *document refresh* is disabled for the database still schedules the document's
  refresh:
  - If you enable the feature before the refresh time, the document will be refreshed in the feature's first run after
    the refresh time.
  - If the refresh time passes while the feature is disabled, the document will be refreshed after the feature is
    enabled, during its first run.
  - In both cases, the document may be refreshed in a later run if the number of documents due for refresh exceeds the
    maximum set for a single run using the Studio option
    [Set max number of documents to process in a single run](https://docs.ravendb.net/7.2/documents/document-refresh/document-refresh-view.md#set-max-number-of-documents-to-process-in-a-single-run).

- #### Conflicted documents
  A document that is in [conflict](https://docs.ravendb.net/7.2/server/clustering/replication/replication-conflicts.md) is not refreshed while
  the conflict remains, even if the refresh time of all its conflicting versions has passed.
  - If the document that resolves the conflict holds a `@refresh` property whose time has passed, the document will be
    refreshed in the feature's first run after the conflict is resolved.
  - A document remains in conflict only if the conflict is not resolved automatically: by default, RavenDB resolves
    conflicts to the most recently modified version of the document (see
    [Conflict Detection](https://docs.ravendb.net/7.2/server/clustering/replication/replication-conflicts.md#conflict-detection)).

- #### Changing or canceling a scheduled refresh
  To change a document's refresh time, set its `@refresh` property to a new time and save the document.  
  To cancel the refresh, remove the `@refresh` property from the document's metadata and save the document.  
  e.g., `del session.advanced.get_metadata_for(user)["@refresh"]`

- #### Reverting documents to revisions
  When you revert a document to a revision
  (or [revert documents to a specific time](https://docs.ravendb.net/7.2/document-extensions/revisions/revert-documents-to-revisions/revert-documents-to-specific-time.md)),
  the reverted document gets the content of the revision **without** the revision's `@refresh` property, even if the revision
  holds this property.
  - The `@refresh` property is omitted from the reverted document because the revision's refresh time was set when
    the revision was created, and has usually already passed by the time of the revert.  
    Keeping the property would refresh the reverted document right after the revert.
  - Since the `@refresh` property is omitted, the reverted document will no longer be scheduled for a refresh unless you set
    its `@refresh` property again.

## Syntax {#syntax}

### ConfigureRefreshOperation

Sends a `RefreshConfiguration` object to the server, to enable or disable *document refresh* for a database and configure the
feature.

```python
ConfigureRefreshOperation(configuration: RefreshConfiguration)
```

Usage:

```python
result = store.maintenance.send(ConfigureRefreshOperation(refresh_configuration))
```

| Parameter | Type | Description |
| - | - | - |
| **configuration** | [RefreshConfiguration](#refreshconfiguration) | The *document refresh* configuration to apply to the database. |

| Return value | |
| - | - |
| [ConfigureRefreshOperationResult](#configurerefreshoperationresult) | Contains `raft_command_index`. |

### Classes

#### RefreshConfiguration

##### `RefreshConfiguration`

**Defines the *document refresh* configuration of a database.**

```python
class RefreshConfiguration:
    def __init__(self, disabled: Optional[bool] = None, refresh_frequency_in_sec: Optional[int] = None): ...
```

| Property | Type | Description |
| - | - | - |
| **disabled** | `bool` | Set to `False` to enable *document refresh* for the database, or to `True` to disable the feature.<br />The default value is `None`, so set the property explicitly. |
| **refresh\_frequency\_in\_sec** | `int` | The interval, in seconds, between the feature's checks for documents to refresh.<br />The value must be greater than 0.<br />If `None`, the default value of 60 seconds applies.<br />On a Community license, the value must be at least 129600 (36 hours). See [Enabling document refresh](#enabling-document-refresh). |

#### ConfigureRefreshOperationResult

##### `ConfigureRefreshOperationResult`

**The result of sending a `ConfigureRefreshOperation` operation to the server.**

```python
class ConfigureRefreshOperationResult:
    def __init__(self, raft_command_index: int): ...
```

| Property | Type | Description |
| - | - | - |
| **raft\_command\_index** | `int` | The Raft index of the command that applied the configuration. |

## See also

- [How to Get and Modify Metadata](https://docs.ravendb.net/7.2/client-api/session/how-to/get-and-modify-entity-metadata.python.md)
- [What is a Change Vector](https://docs.ravendb.net/7.2/server/clustering/replication/change-vector.md)
- [Document Refresh: Studio View](https://docs.ravendb.net/7.2/documents/document-refresh/document-refresh-view.md)
