Skip to main content

(SQLAlchemy - ORM) + Twisted = win

Project description

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 TWISTED_STRATEGY

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 = create_engine(
        "sqlite://", reactor=reactor, strategy=TWISTED_STRATEGY
    )

    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]

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.

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

alchimia-0.7.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alchimia-0.7.0-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file alchimia-0.7.0.tar.gz.

File metadata

  • Download URL: alchimia-0.7.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for alchimia-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7e659356231b420a750828aa7133c78fffc7ded8d1b23f22bbfc877419772fda
MD5 487cecd011b7cd9a4cf041d8c7790ce9
BLAKE2b-256 125b09184196224617fd3b60fdfcf68f3bbad034ec50615b7b12a94fbf941012

See more details on using hashes here.

File details

Details for the file alchimia-0.7.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for alchimia-0.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5eff0380a69f8e83d1fe291022db7bbd0108c943dd3e05721e876f5da734bb9d
MD5 8e266cdf3fdded7e6295740dfffab19d
BLAKE2b-256 90c56878e3318b990920952cbfdd6dfdfd53ad3d8f75217e4be3b1c73db3fc9b

See more details on using hashes here.

Supported by

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