# Asynchronous session

**URL:** <https://community.neo4j.com/t/asynchronous-session/66679>\
**Category:** Python\
**Created:** [March 6, 2024, 1:47pm UTC](https://community.neo4j.com/t/asynchronous-session/66679 "2024-03-06T13:47:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mediotteam](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mediotteam/32/31016_2.png) [@mediotteam](https://community.neo4j.com/u/mediotteam)\
**Post date:** [March 6, 2024, 1:47pm UTC](https://community.neo4j.com/t/asynchronous-session/66679/1 "2024-03-06T13:47:05Z")

</div>

Hi everyone,

I'm a Python developer who is new to Neo4j. I'm interested in using async sessions to interact with the database, but I'm not sure if this is possible.

Is it possible to use async sessions with Neo4j in Python? If so, could you please provide some guidance on how to do this

---

<div class="post-metadata">

**Author:** ![rouven\_bauer](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rouven_bauer/32/16547_2.png) [@rouven\_bauer](https://community.neo4j.com/u/rouven_bauer)\
**Post date:** [March 6, 2024, 1:55pm UTC](https://community.neo4j.com/t/asynchronous-session/66679/2 "2024-03-06T13:55:33Z")

</div>

If with async session you mean async as in the Python keyword and `asyncio` the package, then yes, this is possible. Generally speaking, the async driver API is very closely mirroring the sync API (plus the need to add `await` and `async` here and there). So you can use pretty much any learning material you fancy to get started with Python and Neo4j and easily translate it to async.

E.g., [GraphAcademy](https://graphacademy.neo4j.com/courses/app-python/), the [driver manual](https://neo4j.com/docs/python-manual/current/)

There are also the API docs which highlight the difference between the synchronous and asynchronous APIs: [sync](https://neo4j.com/docs/api/python-driver/current/api.html) vs [async](https://neo4j.com/docs/api/python-driver/current/async_api.html).

Real quick example to go from sync to async:

```auto
from neo4j import (
    AsyncGraphDatabase,
    GraphDatabase,
)

URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "pass")

def sync_main():
    with GraphDatabase.driver(URI, auth=AUTH) as driver:
        driver.verify_connectivity()
        print(
            driver.execute_query("RETURN 1 AS n")
        )

async def async_main():
    async with AsyncGraphDatabase.driver(URI, auth=AUTH) as driver:
        await driver.verify_connectivity()
        print(
            await driver.execute_query("RETURN 1 AS n")
        )

if __name__ == ' __main__':
    sync_main()

    import asyncio
    asyncio.run(async_main())

```

---

<div class="post-metadata">

**Author:** ![mediotteam](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mediotteam/32/31016_2.png) [@mediotteam](https://community.neo4j.com/u/mediotteam)\
**Post date:** [March 6, 2024, 1:59pm UTC](https://community.neo4j.com/t/asynchronous-session/66679/3 "2024-03-06T13:59:34Z")

</div>

Thank you so much for your detailed and helpful answer! Your explanations were very clear and helped me to solve the problem of connecting to the database.

I really appreciate your help.
