Python SDK for Xata

This is a the official low-level Python client for the Xata service. Xata is a Serverless Database that is as easy to use as a spreadsheet, has the data integrity of PostgreSQL, and the search and analytics functionality of Elasticsearch.


Install the xata package from PyPI:

$ pip install xata

While not strictly required, we recommend installing the Xata_CLI and initializing your project with the xata init command:

$ xata init

This will then interactively ask you to select a Database, and store the required connection information in .xatarc and .env. The Python SDK automatically reads those files, but it’s also possible to pass the connection information directly to the xata.Client constructor.

See more information about the installation in the Xata_Python_SDK_Install_Docs.

Example Usage

from xata.client import XataClient

resp ="Avengers", {
    "columns": ["name", "thumbnail"],  # the columns we want returned
    "filter": { "job": "spiderman" },  # optional filters to apply
    "sort": { "name": "desc" }  # optional sorting key and order (asc/desc)
assert resp.is_success()
# [{"id": "spidey", "name": "Peter Parker", "job": "spiderman"}]
# Note it will be an array, even if there is only one record matching the filters

See more examples in the Xata_Python_SDK_Examples_Docs.

Indices and tables