Async database support for Python.
Project description
Databases
Databases gives you simple asyncio support for a range of databases.
It allows you to make queries using the powerful SQLAlchemy Core expression language, and provides support for PostgreSQL, MySQL, and SQLite.
Databases is suitable for integrating against any async Web framework, such as Starlette, Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI.
Documentation: https://www.encode.io/databases/
Community: https://discuss.encode.io/c/databases
Requirements: Python 3.6+
Installation
$ pip install databases
You can install the required database drivers with:
$ pip install databases[postgresql]
$ pip install databases[mysql]
$ pip install databases[sqlite]
Driver support is provided using one of asyncpg, aiomysql, or aiosqlite.
Quickstart
For this example we'll create a very simple SQLite database to run some queries against.
$ pip install databases[sqlite]
$ pip install ipython
We can now run a simple example from the console.
Note that we want to use ipython
here, because it supports using await
expressions directly from the console.
# Create a database instance, and connect to it.
from databases import Database
database = Database('sqlite:///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)
Check out the documentation on making database queries for examples of how to start using databases together with SQLAlchemy core expressions.
— ⭐️ —
Databases is BSD licensed code. Designed & built in Brighton, England.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file databases_extended-0.4.1.tar.gz
.
File metadata
- Download URL: databases_extended-0.4.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63e26225e07b0e431bce9833075c17bb60a9baf043a8d4cbb18480898738badc |
|
MD5 | e8afc8a0fdfc1a335dab0d3daa2ad7de |
|
BLAKE2b-256 | bf0e0daef26c9b3636814786ab8dd022f450a1c1a05bca7403cb9707f2440841 |
File details
Details for the file databases_extended-0.4.1-py2.py3-none-any.whl
.
File metadata
- Download URL: databases_extended-0.4.1-py2.py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c8ae1b152075769770493517ab788a12020a3a249cc9d91ad29cdf8d66534af |
|
MD5 | 1fc8582150d7e0fe3e86055e644e1f24 |
|
BLAKE2b-256 | 81f84d3ead8f3a44a0609ef4abd7345544fe1903de9d6590c3640c7676a45a7f |