Skip to main content

SQLAlchemy Sphinx

travis pypi coveralls

SQLAlchemy Sphinx is a dialect for SQLalchemy which converts SQLAlchemy model into compatible sql for sphinx.

This dialect works for both python 2 and 3. Currently you need to import sqlalchemy_sphinx to properly register for python 3.

Installation

SQLAlchemy Sphinx is available on pypi under the package name sqlalchemy-sphinx, you can get it by running:

pip install sqlalchemy-sphinx

Usage

Defining a Sphinx SQLAlchemy is exactly the same way you would create a sqlalchemy model.

from sqlalchemy import create_engine, Column, Integer, String, BigInteger, Unicode, Enum
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import deferred, sessionmaker

sphinx_engine = create_engine('sphinx://your.sphinx.host:9008')
SphinxBase = declarative_base(bind=sphinx_engine)
SphinxSession = sessionmaker(bind=sphinx_engine)
sphinx_session = SphinxSession()


class MockSphinxModel(Base):
    __tablename__ = "mock_table"
    name = Column(String)
    id = Column(Integer, primary_key=True)
    country = Column(String)
    ranker = deferred(Column(String))
    group_by_dummy = deferred(Column(String))
    max_matches = deferred(Column(String))
    field_weights = deferred(Column(String))

After the model is created we can run queries against the model:

query = session.query(MockSphinxModel).limit(100)
# 'SELECT name, id, country FROM mock_table LIMIT 0, 100'

We can also do matching

base_query = session.query(MockSphinxModel.id)
query = base_query.filter(MockSphinxModel.country.match("US"))
# "SELECT id FROM mock_table WHERE MATCH('(@country US)')"

query = base_query.filter(MockSphinxModel.name.match("adriel"), MockSphinxModel.country.match("US"))
# "SELECT id FROM mock_table WHERE MATCH('(@name adriel) (@country US)')"

Options:

query = session.query(MockSphinxModel.id)
query = query.filter(func.options(MockSphinxModel.field_weights == ["title=10", "body=3"]))
# 'SELECT id FROM mock_table OPTION field_weights=(title=10, body=3)'

query = session.query(MockSphinxModel.id)
query = query.filter(MockSphinxModel.country.match("US"), func.options(MockSphinxModel.max_matches == 1))
# "SELECT id FROM mock_table WHERE MATCH('(@country US)') OPTION max_matches=1"

Metadata

Release files for sqlalchemy-sphinx 0.9.0

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

Source distribution (sdist)

Source distribution for sqlalchemy-sphinx 0.9.0
File Size Uploaded Provenance Actions
sqlalchemy_sphinx-0.9.0.tar.gz 6.0 kB Without provenance Details for sqlalchemy_sphinx-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-sphinx 0.9.0
File Interpreter ABI Platform Actions
sqlalchemy_sphinx-0.9.0-py3-none-any.whl Python 3 none any Details for sqlalchemy_sphinx-0.9.0-py3-none-any.whl

Total release size: 14.1 kB

Release files / sqlalchemy_sphinx-0.9.0.tar.gz

Download URL sqlalchemy_sphinx-0.9.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
80300278a8d51556e238a6088b4f158148e2851532350399e3ea74e922aeca47
BLAKE2b-256 checksum
How to use checksums
4d6f9b6046805de5f370d0686eab853f7a82a1d281a4ad26c8deb8357511c5e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

Release files / sqlalchemy_sphinx-0.9.0-py3-none-any.whl

Download URL sqlalchemy_sphinx-0.9.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4b94109a51e329ffd42abea80a5a09b934e365a3864bdf924551638b2b9c9e9
BLAKE2b-256 checksum
How to use checksums
06324f620a205c37af5efa5c803fcc306a123bd670a0b5384e8dc51df700b2d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

Security for sqlalchemy-sphinx 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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