---
title: "Session: Deleting Entities"
url: "https://docs.ravendb.net/6.2/client-api/session/deleting-entities"
version: "6.2"
language: "python"
---

# Session: Deleting Entities

> Client language: Python. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.md), [Java](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.java.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.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."

Entities can be marked for deletion by using the `delete()` method, but will not be removed from the server until `save_changes()` is called.

## Syntax

```python
def delete(self, key_or_entity: Union[str, object], expected_change_vector: Optional[str] = None) -> None:
  ...
```

| Parameters | | |
| - | - | - |
| **key\_or\_entity** | `str` or `object` | ID of the document or instance of the entity to delete |
| **expected\_change\_vector** | `str` | a change vector to use for concurrency checks |

## Example I

```python
employee = session.load("employees/1")

session.delete(employee)
session.save_changes()
```

> **Note:** Concurrency on Delete {#concurrency-on-delete}
>
> If use\_optimistic\_concurrency is set to 'True' (default 'False'), the delete() method will use loaded 'employees/1' change vector for concurrency check and might throw ConcurrencyException.

## Example II

```python
session.delete("employees/1")
session.save_changes()
```

> **Note:** Concurrency on Delete {#concurrency-on-delete-1}
>
> The delete() method will not do any change vector based concurrency checks because the change vector for 'employees/1' is unknown.

> **Info:** Information {#information}
>
> If entity is **not** tracked by session, then executing:
>
> ```python
> session.delete("employees/1")
> ```
>
> is equal to doing:
>
> ```python
> session.advanced.defer(DeleteCommandData("employees/1", change_vector=None))
> ```
>
> > **Note:** Change Vector in DeleteCommandData {#change-vector-in-deletecommanddata}
> >
> > In this sample the change vector is None - this means that there will be no concurrency checks. A not-None and valid change vector value will trigger a concurrency check.
>
> You can read more about defer operations [here](https://docs.ravendb.net/6.2/client-api/session/how-to/defer-operations.python.md).

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.python.md)
- [Opening a Session](https://docs.ravendb.net/6.2/client-api/session/opening-a-session.python.md)
- [Loading Entities](https://docs.ravendb.net/6.2/client-api/session/loading-entities.python.md)
- [Saving Changes](https://docs.ravendb.net/6.2/client-api/session/saving-changes.python.md)
- [How To: Enable Optimistic Concurrency](https://docs.ravendb.net/6.2/client-api/session/configuration/how-to-enable-optimistic-concurrency.python.md)
- [Query Overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.python.md)
- [Basics](https://docs.ravendb.net/6.2/indexes/querying/query-index.python.md)
- [What is a Document Store](https://docs.ravendb.net/6.2/client-api/what-is-a-document-store.md)
