Skip to main content

Morcilla

Test Suite Package version

Morcilla gives you simple and high-performant asyncio support for a range of databases. The project is a hard fork of encode/databases.

It allows you to make queries using the powerful SQLAlchemy Core expression language, and provides support for PostgreSQL and SQLite.

Morcilla is suitable for integrating against any async Web framework.

Requirements: Python 3.8+


Installation

$ pip install morcilla

You can install the required database drivers with:

$ pip install morcilla[postgresql]
$ pip install morcilla[sqlite]

Default driver support is provided using one of asyncpg or aiosqlite.

Note that if you are using any synchronous SQLAlchemy functions such as engine.create_all() or alembic migrations then you still have to install a synchronous DB driver: psycopg2 for PostgreSQL.


Quickstart

For this example we'll create a very simple SQLite database to run some queries against.

$ pip install morcilla[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 morcilla 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 morcilla together with SQLAlchemy core expressions.

Why hard fork?

Morcilla satisfies one particular requirement that Athenian has: to provide the best performance at any cost, while sacrificing as little developer experience as possible. Hence it rejects the uniform Record interface that encode/databases provides in favor of native backend objects. Thus there is no guarantee that the same code will work equally successful for all the supported DB backends. Besides, we have optimized Morcilla for asyncpg, so e.g. asyncpg performs JSON serialization and deserialization instead of sqlalchemy for performance boost. The character of the changes is very much breaking the existing code, and they should not be submitted upstream.

Finally, we are going to add new backends such as Clickhouse in the future.

Why "morcilla"?

Morcilla means blood sausage in Spanish. So the name reflects the bloody mess gory nature of the code.

Release files for morcilla 0.5.37

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for morcilla 0.5.37
File Size Uploaded
morcilla-0.5.37.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for morcilla 0.5.37
File Interpreter ABI Platform
morcilla-0.5.37-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / morcilla-0.5.37.tar.gz

Download URL morcilla-0.5.37.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9d12e4ce5bf0c190d0669110f360dbeb86f90c4c5583445dfabd7ccb0e720437
BLAKE2b-256 checksum
How to use checksums
6e34bfb0b357c8e5cb7bcfc20d130df954e75181209660f53800068cf65048e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release files / morcilla-0.5.37-py3-none-any.whl

Download URL morcilla-0.5.37-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49124b66a284b2d37f5ae4465e5e60c861c1bdc45e21d8c08fdb12c642611485
BLAKE2b-256 checksum
How to use checksums
0f7c140753b53a895e34eb113783ef3b7bfae0ca009e8bbc0811852ba0e8721b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page