---
title: current_transaction (Python agent API)
source: https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/currenttransaction-python-agent-api
---

## Syntax

```py
newrelic.agent.current_transaction(active_only=True)
```

Returns an object corresponding to the current transaction.

## Description

Use `current_transaction` to retrieve the object representing the current [transaction](https://docs.newrelic.com/docs/accounts-partnerships/education/getting-started-new-relic/glossary#transaction). It will return `None` if there is no active transaction.

## Parameters

| Parameter               | Description                                                                                                                                                                                                                |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `active_only` _boolean_ | Optional. Default is `True`, meaning it will only return active transactions. If set to `False`, the call is capable of returning a transaction that has ended or stopped (for example, if `end_of_transaction` was used). |

## Return values

Returns a transaction object corresponding to current transaction. Returns `None` if there is no active transaction.

## Examples

### Get the current transaction [#function-trace-example]

```py
import newrelic.agent

@newrelic.agent.background_task()
def main():
    transaction = newrelic.agent.current_transaction()
```
