Skip to main content

Lightweight Python client for Apache Solr.

Project description

aiosolr

AsyncIO Python client for Apache Solr

Requirements

This project requires Python 3.6+

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, collection, and timeout.

Note: collection may also be passed at query time

import aiosolr

solr = aiosolr.Solr(host=localhost, collection="example", port=8983)

Once you have your Solr instance, there are methods available for querying.

You can use Solr's built-in get handler with the get method like:

solr.get(document_id)

to retrieve a single document.

You can use a pre-defined suggestions handler by using the suggestions method like:

solr.suggestions("suggest_handler", query="asdf")

You can also use the suggestions method to build your suggestions like:

solr.suggestions("suggest_handler", build=True)

Note: handler is 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".

solr.query(handler="my_handler", query="asdf")

You can use the update method to access Solr's built-in update handler like:

solr.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 method which can be used to strip out unwanted characters. The function signature allows the following arguments:

@staticmethod
def clean(
    query,  # end user query
    allow_html_tags=False,
    allow_http=False,
    allow_wildcard=False,
    escape_chars=(":", r"\:"),  # tuple of (replace_me, replace_with)
    max_len=200,
    remove_chars=r'[\&\|\!\(\)\{\}\[\]\^"~\?\\\*]',  # regex of chars to remove
):

Once you are finished with the Solr instance, you should call the method close to cleanup sessions like:

await solr.close()

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

aiosolr-2.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiosolr-2.2.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file aiosolr-2.2.1.tar.gz.

File metadata

  • Download URL: aiosolr-2.2.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

File hashes

Hashes for aiosolr-2.2.1.tar.gz
Algorithm Hash digest
SHA256 6b696b4593158fbb69215e515519e35521e965ce8eb04cfebed1987393e916ff
MD5 e83d1034483229e8b057625abb6cbdae
BLAKE2b-256 8ee91fdbcf25a053cf879fc38cc905d52242fa6b4a19aa59ce3b7c85e7be1210

See more details on using hashes here.

File details

Details for the file aiosolr-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: aiosolr-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

File hashes

Hashes for aiosolr-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a89c5240f2ff286bb42a2f995c325f48693aacaff22d4eccef023a12c0ea35b
MD5 9fb8ace5330ddd2fad113787cd098e6d
BLAKE2b-256 6dda437e162b796c0725327dccea3177c15eabab1e7ce1390a74823917a81d5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page