aiosolr
AsyncIO Python client for Apache Solr
Requirements
This project requires Python 3.7+
Installation
To install with pip
pip install aiosolr
Usage
The connection to the Solr backend is defined during object initialization. The accepted kwargs to
init are scheme, host, port, and collection.
collectionmay optionally be passed at query time
import aiosolr
client = aiosolr.Client(host=localhost, collection="example", port=8983)
Alternatively you may instantiate via passing connection_url like:
import aiosolr
client = aiosolr.Client(connection_url="http://host:1234/path/to/solr/collection")
Once you have your aiosolr.Client instance, set up the session:
await client.setup()
There are methods available for querying. You can use Solr's built-in get handler with the get
method to retrieve a single document:
await client.get(document_id)
You can use a pre-defined suggestions handler by using the suggestions method:
await client.suggestions("suggest_handler", query="asdf")
You can also use the suggestions method to build your suggestions:
await client.suggestions("suggest_handler", build=True)
handleris a required argument for suggestions unlike for get or query
You can use the query method to query your search handler. The default handler used is select.
If you would like spellcheck suggestion turned on, pass spellcheck=True (default is False).
await client.query(handler="my_handler", query="asdf", spellcheck=True)
If spellcheck is True the query method returns a tuple with the first element being an array of
documents and the 2nd element being an array of spellcheck suggestions. Otherwise, the query method
returns a simple array of documents.
You can use the update method to access Solr's built-in update handler like:
await client.update(my_data)
At any point that you need to commit data to your collection you can use the commit method.
Arguments should be the handler (update by default) and soft as a boolean indicating whether
it should be a hard or soft commit (defaults to False).
There is one more method you might want to use before querying Solr especially if the query is
coming from an untrusted end user. There is a clean_query method which can be used to strip out
unwanted characters. Use it like:
trusted_query = aiosolr.clean_query(users_query)
Once you are finished with the Solr instance, you should call the method close to cleanup sessions
like:
await client.close()
Timeouts
You can initialize the client with read_timeout and write_timeout to limit how long to wait for
requests to complete. read_timeout applies to get and query whereas write_timeout applies to
update:
import aiosolr
client = aiosolr.Client(connection_url=connection_url, read_timeout=5, write_timeout=30)
You can override the timeouts for a specific request:
await client.get(document_id, read_timeout=1) # I'm in a hurry
await client.update(doc, write_timeout=60) # this is a large request so we expect it to take a long time
aiosolrusesasyncio.wait_forinternally, so if a timeout occurs the exception raised isasyncio.TimeoutError.
Debugging
To get more information from the Client you can initialize with debug=True:
import aiosolr
client = aiosolr.Client(host=localhost, collection="example", port=8983, debug=True)
This sets the aiosolr logger to DEBUG level, and also sets the internally used HTTP session
(provided by aiohttp) to the DEBUG level. This
makes it easier to see the actual network requests going to Solr.
Metadata
Release files for aiosolr 5.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiosolr-5.0.2.tar.gz | 19.0 kB | Without provenance | Details for aiosolr-5.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiosolr-5.0.2-py3-none-any.whl | Python 3 | none | any | Details for aiosolr-5.0.2-py3-none-any.whl |
Total release size: 28.5 kB
Release files / aiosolr-5.0.2.tar.gz
| Download URL | aiosolr-5.0.2.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
678fb1e46097e9760f1f34372cd2a22a472d0db7718eef600659d2b1a660397e
|
|
BLAKE2b-256 checksum How to use checksums |
16be96b51aa838206a62e1e86d3be2bffba402d02b72541d89ec83573e87b86f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / aiosolr-5.0.2-py3-none-any.whl
| Download URL | aiosolr-5.0.2-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a69f9d7c3986d8effe62d444c9ec3af7b93a2969717439e5a1f9b8f850127cb
|
|
BLAKE2b-256 checksum How to use checksums |
31483ba3ddf810ae95dd480ff6d093156107e098fb10a05fefacf76c15584a4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Security for aiosolr 5.0.2
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.