DEV Community

Cover image for Discover the Xata SDK for Python
Joan for Xata

Posted on • Updated on • Originally published at xata.io

Discover the Xata SDK for Python

At the start, Xata's initial focus was to make things better for developers using Jamstack. This led to us creating content that predominantly focused on providing a robust TypeScript offering.

Motivated by our enthusiasm for connecting with developers, we soon launched a Python SDK, though it initially had just basic capabilities. Since that initial release, a few things have changed. The world has gone AI-crazy and Python has unofficially become the language of choice for AI/ML. This has coincided with our introduction of vector embeddings and the integration of OpenAI's ChatGPT for your data.

As the Python SDK user base has grown steadily over the last few months, we have actively gathered feedback about what users like and dislike.

Version 1.0.0 of our Python SDK is available.

PEP-8 FTW!

Previously, we received feedback that the SDK didn't feel pythonic! Initially, in the 0.x releases, the API was generated one-by-one from our OpenAPI specification, which resulted in a non-pythonic API. For this release, we have aligned as much as possible with the PEP-8 standard.

Speed improvements

Under the hood, we've made adjustments to how connections are managed and reused. The refactoring has yielded significant performance improvements across the board. The most notable ones include accelerated operation speeds:

Operation Speedup (on average)
Get a single record 5.95x
Insert a single record 4.95x
Insert 100 records with transactions 2.22x

How to migrate to 1.x?

Migrating to a new major version can be tough due to the need to understand breaking changes and features that are no longer available. With that in mind, our goal was to minimize the impact while still implementing necessary changes for the greater good. You can check out the full migration guide in our docs.

The most impactful user-facing change is the renaming of the API surface [xata-py#93]. Additionally, some API endpoint calls were simplified to remove unnecessary code bloat.

Previously in 0.x, you needed to investigate the payload shape and be specific about the region and branch name.

xata.databases().createDatabase("new_db",
  {
    "region": "us-east-1",
    "branchName": "main",
  }
)
Enter fullscreen mode Exit fullscreen mode

In version 1.0.*, we've redesigned the API interface to incorporate payload options directly into the method signature. We've also optimized the SDK's internal values to make assumptions to reuse the SDK internal values, like the region. This results in a more streamlined API structure, and you can achieve functionality using:

xata.databases().create("new_db")
Enter fullscreen mode Exit fullscreen mode

What happens to 0.x?

We will continue providing support for the 0.x version of the Xata Python SDK through maintenance releases for an additional year. During this time, new API enhancements and security fixes will be introduced; however, no backports of helpers or other improvements are planned. The 0.x SDK version will be sunsetted by September 1st, 2024.

What’s next?

Check out our documentation and let us know what you think. We’d love to hear from you! If you think something is missing or you found a bug, open a ticket in the xata-py repository. All contributions are welcome. You can also follow us on Twitter or join us in Discord.

Is there a language you wished we supported natively but don't today? Feel free to open up a feature request or check-in with our amazing community. The xata-go SDK was initiated by Kerdo and is hosted on GitHub. mrkresnofatih also added the terraform-provider-xata to provision Xata. If you're interested in contributing, feel free to reach out with any questions! Happy building πŸ˜„

Top comments (0)