Package: databasez
Databasez🚀 Async database support for Python. 🚀Documentation:https://databasez.tarsild.io📚Source Code:https://github.com/tarsil/databasezMotivationThere is a great package fromEncodethat was doing what
this package was initially forked to do but Encode is also very busy with other projects and
without the proper time to maintain the so much required package.From a need to extend to new drivers and newest technologies and adding extra features common and
useful to the many,Databaseswas forked to becomeDatabasez.This package is 100% backwards compatible withDatabasesfrom Encode and will remain like this for the time being but adding extra features and regular
updates as well as continuing to be community driven.By the time this project was created, Databases was yet to merge possible SQLAlchemy 2.0 changes
from the author of this package and therefore, this package aims to unblock
a lot of the projects out there that want SQLAlchemy 2.0 with the best of databases with new features.A lot of packages depends of Databases and this was the main reason for the fork ofDatabasez.It allows you to make queries using the powerfulSQLAlchemy Coreexpression language, and provides support for PostgreSQL, MySQL, SQLite and MSSQL.Databasez is suitable for integrating against any async Web framework, such asEsmerald,Starlette,Sanic,Responder,Quart,aiohttp,Tornado, orFastAPI.Databasez was built for Python 3.8+ and on the top of the newestSQLAlchemy 2and gives you
simple asyncio support for a range of databases.Special notesThis package couldn't exist withoutDatabasesand the continuous work
done by the amazing team behind it. For that reason, thank you!Installation$pipinstalldatabasezIf you are interested in using thetest client, you can also install:$pipinstalldatabasez[testing]What does databasez support at the momentDatabasez currently supportssqlite,postgres,mysqlandsql server. More drivers can and
will be added in the future.Database drivers supported are:asyncpg- For postgres.aiopg- For postgres.aiomysql- For MySQL/MariaDB.asyncmy- For MySQL/MariaDB.aiosqlite- For SQLite.aioodbc- For MSSQL (SQL Server).Driver installationYou can install the required database drivers with:Postgres$pipinstalldatabasez[asyncpg]or$pipinstalldatabasez[aiopg]MySQL/MariaDB$pipinstalldatabasez[aiomysql]or$pipinstalldatabasez[asyncmy]SQLite$pipinstalldatabasez[aiosqlite]MSSQL$pipinstalldatabasez[aioodbc]!!! Note
Note that if you are using any synchronous SQLAlchemy functions such asengine.create_all()oralembicmigrations then you still have to install a synchronous DB driver:psycopg2for PostgreSQL,pymysqlfor MySQL andpyodbcfor SQL Server.QuickstartFor a simple quickstart example, we will be creating a simple SQLite database to run some queries
against.First, install the required drivers forSQLiteandipython. Theipythonis to have an
interactive python shell with some extras. IPython also supportsawait, which is exactly
what we need.See more detailsabout it.Install the required drivers$pipinstalldatabasez[aiosqlite]$pipinstallipythonNow from the console, we can run a simple example.# Create a database instance, and connect to it.fromdatabasezimportDatabasedatabase=Database("sqlite+aiosqlite:///example.db")awaitdatabase.connect()# Create a table.query="""CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)"""awaitdatabase.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},]awaitdatabase.execute_many(query=query,values=values)# Run a database query.query="SELECT * FROM HighScores"rows=awaitdatabase.fetch_all(query=query)print("High Scores:",rows)Check out the documentation onmaking database queriesfor examples of how to start using databasez together with SQLAlchemy core expressions.