---
title: getActiveSession
description: "SparkSession.getActiveSession class in PySpark: Returns the active SparkSession for the current thread, returned by the builder."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/sparksession/getActiveSession
---

# getActiveSession

Returns the active `SparkSession` for the current thread, returned by the builder.

## Syntax

```
SparkSession.getActiveSession()
```

## Returns

`SparkSession` or `None`

## Examples

```python
s = SparkSession.getActiveSession()
df = s.createDataFrame([('Alice', 1)], ['name', 'age'])
df.select("age").show()
# +---+
# |age|
# +---+
# |  1|
# +---+
```
