What is Xata?
asyncpg

Connect to Postgres with asyncpg

Edit on GitHub

To connect to Xata with asyncpg you can use the following code. Please replace the parameters as indicated on the connect to Postgres page.

import asyncpg
import asyncio

async def get_server_version():
  connection = await asyncpg.connect(
    database="<DATABASE_NAME>:<BRANCH>",
    user="<WORKSPACE_ID>",
    password="<API_KEY>",
    host="<REGION>.sql.xata.sh",
    port=5432,
  )
  version = connection.get_server_version()
  print(version)
  await connection.close()

asyncio.run(get_server_version())

# Print: Postgres version is ServerVersion(major=15, minor=0, micro=1, releaselevel='final', serial=0)