{"id":22404,"library":"sqlalchemy-solr","title":"SQLAlchemy Solr Dialect","description":"Apache Solr dialect for SQLAlchemy, allowing Solr to be queried using SQLAlchemy ORM and Core. Current version 0.2.4.3, supports Python >=3.8 and Solr 6.x-9.x. Release cadence is irregular.","status":"active","version":"0.2.4.3","language":"python","source_language":"en","source_url":"https://github.com/aadel/sqlalchemy-solr","tags":["sqlalchemy","solr","database","dialect","apache-solr"],"install":[{"cmd":"pip install sqlalchemy-solr","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required - integrates with SQLAlchemy Core/ORM","package":"sqlalchemy>=1.4,<2.0","optional":false},{"reason":"Required - HTTP client for Solr","package":"requests>=2.25.1,<3.0","optional":false},{"reason":"Required - XML parsing for Solr responses","package":"lxml>=4.0,<6.0","optional":false}],"imports":[{"note":"create_engine is from SQLAlchemy, not sqlalchemy-solr. The dialect is registered via URL prefix.","wrong":"from sqlalchemy_solr import create_engine","symbol":"create_engine","correct":"from sqlalchemy import create_engine"},{"note":"Utility to check Solr version compatibility.","symbol":"savoir","correct":"from sqlalchemy_solr import savoir"}],"quickstart":{"code":"from sqlalchemy import create_engine, text\nimport os\n\n# Solr URL, default 'http://localhost:8983/solr'\nsolr_url = os.environ.get('SOLR_URL', 'http://localhost:8983/solr')\n# Create engine with solr:// prefix, database name is Solr core/collection\nengine = create_engine(f'solr://admin:@localhost:8983/solr/collection1')\nwith engine.connect() as conn:\n    result = conn.execute(text(\"SELECT * FROM collection1 LIMIT 10\"))\n    for row in result:\n        print(row)\n","lang":"python","description":"Connect to a Solr core and run a basic SQL query."},"warnings":[{"fix":"Use URL format: solr://username:password@host:port/solr/core_name","message":"Engine URL must use 'solr://' prefix. The username and password are for HTTP basic auth, not Solr authentication. Database name is the Solr core/collection name.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade Python to 3.8+.","message":"Python 3.8 support is the minimum; Python 3.7 and earlier will not work.","severity":"deprecated","affected_versions":">=0.2.4.0"},{"fix":"If using Solr >=9.0, enable cache by setting environment variable SQLALCHEMY_SOLR_CACHE=1 before engine creation.","message":"SQL compilation cache is disabled by default for Solr <9.0. This may impact performance.","severity":"gotcha","affected_versions":">=0.2.4.2"},{"fix":"Update code to handle int/float/datetime values directly.","message":"From version 0.2.4.0, the dialect returns native Python types instead of strings. Code relying on string results may break.","severity":"breaking","affected_versions":">=0.2.4.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install SQLAlchemy 1.4.x: pip install 'sqlalchemy>=1.4,<2.0'","cause":"Missing or incompatible SQLAlchemy version (e.g., 2.x).","error":"sqlalchemy.exc.ArgumentError: Could not determine version of SQLAlchemy"},{"fix":"Start Solr or check host/port in connection string.","cause":"Solr server not running or port incorrect.","error":"requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8983): Max retries exceeded"},{"fix":"Upgrade to >=0.2.4.0: pip install --upgrade sqlalchemy-solr","cause":"Older version of sqlalchemy-solr without savoir module.","error":"ImportError: cannot import name 'savoir' from 'sqlalchemy_solr'"},{"fix":"Use existing core name as database in URL.","cause":"Specified Solr core/collection does not exist.","error":"solr.exceptions.SolrException: Error from Solr: org.apache.solr.common.SolrException: Collection not found: mycore"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}