I wrote a minimal database dialect for SQLAlchemy that doesn’t really belong in the core. How do I make it work as its own Python package?
I wrote a minimal database dialect for SQLAlchemy that doesn’t really belong in the
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When SQLAlchemy resolves a database url
example://...it will first try to find it inimport sqlalchemy.dialects.example. If that doesn’t work it falls back topkg_resources.iter_entry_points('sqlachemy.databases').Put the new dialect in a package using
setuptools, include an entry point named after your dialect, runpython setup.py developorpython setup.py install, and SQLAlchemy should be able to find the dialect.In
setup.py:example_sa:base.dialectmeansimport example_sa; return example_sa.base.dialect.After installing this package,
pkg_resources.iter_entry_points(group)yieldspkg_resources.EntryPointinstances fromgroup. Call.load()on theEntryPointwithentrypoint.name='example'and you getexample_sa.base.dialect.I was pleasantly surprised at how easy it is to write new dialects for SQLAlchemy 0.6. If your database has just a few quirks compared to standard SQL, chances are you will be able to inherit from the standard (MySQL-like) SQL dialect, define your database’s keywords, and copy the implementation of those quirks (like
SELECT TOP 10instead ofSELECT ... LIMIT 10) from an existing dialect.