Client for the Solr search service
Project description
solrpy
solrpy is a Python client for Solr, an enterprise search server built on top of Lucene. solrpy allows you to add documents to a Solr instance, and then to perform queries and gather search results from Solr using Python.
- Supports Solr 1.2 through 10.x
- Automatic Solr version detection with runtime feature gating
- Python 3.10+ required
Installation
pip install solrpy
Or with Poetry:
poetry add solrpy
Overview
import solr
# create a connection to a solr server
s = solr.Solr('http://localhost:8983/solr/mycore')
# the server version is auto-detected
print(s.server_version) # e.g. (9, 4, 1)
# check if the server is reachable
print(s.ping()) # True
# add a document to the index
doc = {
"id": 1,
"title": "Lucene in Action",
"author": ["Erik Hatcher", "Otis Gospodnetić"],
}
s.add(doc, commit=True)
# do a search
response = s.select('title:lucene')
for hit in response.results:
print(hit['title'])
More powerful queries
Optional parameters for query, faceting, highlighting, and more like this
can be passed in as Python parameters to the query method. Convert the
dot notation (e.g. facet.field) to underscore notation (e.g. facet_field)
so that they can be used as parameter names.
response = s.select('title:lucene', facet='true', facet_field='subject')
If the parameter takes multiple values, pass them in as a list:
response = s.select('title:lucene', facet='true', facet_field=['subject', 'publisher'])
Version detection
solrpy automatically detects the connected Solr version and gates features
accordingly. If a feature requires a newer Solr version than what is
connected, a SolrVersionError is raised with a clear message.
import solr
s = solr.Solr('http://localhost:8983/solr/mycore')
print(s.server_version) # (6, 6, 6)
Tests
Tests require a running Solr instance. Using Docker:
docker run -d --name solr-dev -p 8983:8983 solr:6.6 solr-precreate core0
poetry run pytest tests/
Changelog
1.0.2
mypy --strictpasses with zero errors onsolr/package- Added type hints to all internal classes (
ResponseContentHandler,Node,Results,UTC) - Fixed
endElementvariable shadowing for type safety
1.0.1
- Added type hints to all public methods in
solr/core.pyandsolr/paginator.py - Added
solr/py.typedmarker file for PEP 561 compatibility - Added
mypyto dev dependencies - mypy passes with zero errors on
solr/package
0.9.11
- Added JSON response parser (
parse_json_response) - Added
Solr.ping()convenience method - Added
always_commitconstructor option for auto-commit behavior - Added gzip response support (
Accept-Encoding: gzip)
0.9.10
- Added pyproject.toml metadata (authors, maintainers, classifiers, keywords)
- Added Sphinx documentation (quickstart, API reference, version detection, changelog)
- Rewrote README.md with current API examples and Docker test instructions
- Updated CLAUDE.md development guidelines
0.9.9
- Removed deprecated
encoder/decoderattributes andcodecsimport - Fixed
commit(_optimize=True)to correctly issue<optimize/>command - Added test coverage for
<double>XML type parsing - Added test coverage for named
<result>tag handling - Added Solr version auto-detection (
server_version) - Added
SolrVersionErrorexception andrequires_versiondecorator - Removed all Python 2 compatibility code (Python 3.10+ only)
- Migrated from setuptools to Poetry
- Bumped version to 0.9.9
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solrpy-1.0.2.tar.gz.
File metadata
- Download URL: solrpy-1.0.2.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-14-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2efbb21d438c3f4e49fab2c3e525773fc93b1ebc5633c497914f1a3307a7b3e7
|
|
| MD5 |
06cf74be54c6aa07204d8fb32b725c71
|
|
| BLAKE2b-256 |
cffb0450ea0c269202b31c0769182719bbdc54d75347b0d925b999824e535c7f
|
File details
Details for the file solrpy-1.0.2-py3-none-any.whl.
File metadata
- Download URL: solrpy-1.0.2-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-14-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5943f75eebf0103acd15280393cf6f1f33c8db7015342404a7da0bb81df84f6
|
|
| MD5 |
d3162819486e0d6b6db7d157481ca744
|
|
| BLAKE2b-256 |
e976f0948b53238581ed24f6830dd787006aacdd8ea227facc0d21eb0663e599
|