Skip to main content

Performant async database support for Python.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morcilla-0.5.37.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

morcilla-0.5.37-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file morcilla-0.5.37.tar.gz.

File metadata

  • Download URL: morcilla-0.5.37.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for morcilla-0.5.37.tar.gz
Algorithm Hash digest
SHA256 9d12e4ce5bf0c190d0669110f360dbeb86f90c4c5583445dfabd7ccb0e720437
MD5 0960f0cbbe91eb8e0d5123910cd7e27f
BLAKE2b-256 6e34bfb0b357c8e5cb7bcfc20d130df954e75181209660f53800068cf65048e1

See more details on using hashes here.

File details

Details for the file morcilla-0.5.37-py3-none-any.whl.

File metadata

  • Download URL: morcilla-0.5.37-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for morcilla-0.5.37-py3-none-any.whl
Algorithm Hash digest
SHA256 49124b66a284b2d37f5ae4465e5e60c861c1bdc45e21d8c08fdb12c642611485
MD5 ae95d39776a884fa0517cf5589e45414
BLAKE2b-256 0f7c140753b53a895e34eb113783ef3b7bfae0ca009e8bbc0811852ba0e8721b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page