Skip to main content

alchimia lets you use most of the SQLAlchemy-core API with Twisted, it does not allow you to use the ORM.

Getting started

from alchimia import wrap_engine

from sqlalchemy import (
    create_engine, MetaData, Table, Column, Integer, String
)
from sqlalchemy.schema import CreateTable

from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react


@inlineCallbacks
def main(reactor):
    engine = wrap_engine(reactor, create_engine("sqlite://"))

    metadata = MetaData()
    users = Table("users", metadata,
        Column("id", Integer(), primary_key=True),
        Column("name", String()),
    )

    # Create the table
    yield engine.execute(CreateTable(users))

    # Insert some users
    yield engine.execute(users.insert().values(name="Jeremy Goodwin"))
    yield engine.execute(users.insert().values(name="Natalie Hurley"))
    yield engine.execute(users.insert().values(name="Dan Rydell"))
    yield engine.execute(users.insert().values(name="Casey McCall"))
    yield engine.execute(users.insert().values(name="Dana Whitaker"))

    result = yield engine.execute(users.select(users.c.name.startswith("D")))
    d_users = yield result.fetchall()
    # Print out the users
    for user in d_users:
        print("Username: %s" % user[users.c.name])
    # Queries that return results should be explicitly closed to
    # release the connection
    result.close()

if __name__ == "__main__":
    react(main, [])

Documentation

The documentation is all on Read the Docs.

Limitations

There are some limitations to alchimia's ability to expose the SQLAlchemy API.

  • Some methods simply haven’t been implemented yet. If you file a bug, we’ll implement them! See CONTRIBUTING.rst for more info.

  • Some methods in SQLAlchemy either have no return value, or don’t have a return value we can control. Since most of the alchimia API is predicated on returning Deferred instances which fire with the underlying SQLAlchemy instances, it is impossible for us to wrap these methods in a useful way. Luckily, many of these methods have alternate spelling. The docs call these out in more detail.

Metadata

Release files for alchimia 0.8.1

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

Source distribution (sdist)

Source distribution for alchimia 0.8.1
File Size Uploaded
alchimia-0.8.1.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alchimia 0.8.1
File Interpreter ABI Platform
alchimia-0.8.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 24.9 kB

Release files / alchimia-0.8.1.tar.gz

Download URL alchimia-0.8.1.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c41b42e629ff8139b64dd28341704bdd5734be28d87b3e46259241f8b0173b8a
BLAKE2b-256 checksum
How to use checksums
d986c63b218ad606a5538cbd777c0b926467e849e87b92cc863039843ebdc75c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / alchimia-0.8.1-py2.py3-none-any.whl

Download URL alchimia-0.8.1-py2.py3-none-any.whl
Size 6.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
161ebe7076d8b5feda728df7128b2f5aea1d26d9b67cf33212ebaaeb26cff1b7
BLAKE2b-256 checksum
How to use checksums
d2417bf9f947d845318d0c8603c98e8dfae39151398793d5bb46ad9757139062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
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