Async Database Support for Python

Emily Techscribe Avatar

·

Are you on the lookout for a reliable, high-performance async database support package for your Python projects? Look no further! Introducing Databasez, a powerful and versatile library that simplifies database queries and enhances performance. Whether you’re building a web application or working on a data-driven project, Databasez has got you covered.

Databasez Logo

A Solution Derived from Encode

Databasez initially started as a fork of the popular Databases package from Encode. The aim of Databasez is to address the need for extended driver support, compatibility with newer technologies, and the incorporation of additional features required by the community. While ensuring backward compatibility with Databases, Databasez continues to evolve and provide regular updates, making it a truly community-driven project.

Seamless Integration with Web Frameworks

One of the standout features of Databasez is its compatibility with various async web frameworks. Whether you’re working with Esmerald, Starlette, Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI, Databasez seamlessly integrates with your chosen web framework, providing simple asyncio support for a wide range of databases.

Wide Range of Database Support

Databasez currently supports popular databases including sqlite, postgres, mysql, and sql server. With each update, more drivers will be added to increase the range of supported databases. The current list of supported drivers includes:

Installing the required drivers for your chosen database is a breeze and allows you to take full advantage of Databasez functionalities.

Getting Started with Databasez

To get started with Databasez, simply install the package using pip:

shell
$ pip install databasez

Depending on your database choice, you may also need to install the corresponding driver. For example, to use PostgreSQL, you can install the asyncpg driver:

shell
$ pip install databasez[asyncpg]

The Databasez documentation provides detailed installation instructions for each driver and database.

Real-World Use Case: High Scores

Let’s take a quick look at a real-world use case to illustrate the power of Databasez. Suppose you’re developing a gaming application and need to store high scores in a database. Here’s a simple example of how you can achieve this using Databasez and SQLite:

“`python

Create a database instance and connect to it.

from databasez import Database

database = Database(“sqlite+aiosqlite:///example.db”)
await database.connect()

Create a table.

query = “””CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)”””
await database.execute(query=query)

Insert some data.

query = “INSERT INTO HighScores(name, score) VALUES (:name, :score)”
values = [
{“name”: “Daisy”, “score”: 92},
{“name”: “Neil”, “score”: 87},
{“name”: “Carol”, “score”: 43},
]
await database.execute_many(query=query, values=values)

Run a database query.

query = “SELECT * FROM HighScores”
rows = await database.fetch_all(query=query)

print(“High Scores:”, rows)
“`

As you can see, Databasez simplifies the process of creating a database connection, executing queries, and fetching results. With Databasez, managing high scores or any other database-related tasks becomes a breeze.

Stay Up to Date and Contribute

Databasez is a community-driven project that thrives on continuous improvement and feedback. The project is actively maintained, and updates are regularly released to incorporate new features and address issues. You can find the complete documentation at https://databasez.tarsild.io, where you can learn more about making database queries using SQLAlchemy core expressions and explore advanced techniques.

If you’re interested in contributing to the project, you can find the source code and contribute on GitHub.

Conclusion

Databasez opens up a world of possibilities for handling async database operations in Python. With its exceptional compatibility, extensive database support, and easy integration with web frameworks, Databasez empowers developers to build efficient and scalable applications. Whether you’re a web developer, data scientist, or software engineer, Databasez is a must-have tool in your Python toolbox.

Give Databasez a try today, and experience the power of async database support in Python!

Note: This article includes information and excerpts from the Databasez documentation. Special thanks to the Encode team for their initial work on Databases, which paved the way for the development of Databasez.

Leave a Reply

Your email address will not be published. Required fields are marked *