aiosolr


Nameaiosolr JSON
Version 5.0.1 PyPI version JSON
download
home_pageNone
SummaryLightweight AsyncIO Python client for Apache Solr
upload_time2024-04-25 02:55:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords solr asyncio aiohttp search
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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`.

> `collection` may optionally be passed at query time

```python
import aiosolr

client = aiosolr.Client(host=localhost, collection="example", port=8983)
```

Alternatively you may instantiate via passing `connection_url` like:

```python
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:

```python
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:

```python
await client.get(document_id)
```

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

```python
await client.suggestions("suggest_handler", query="asdf")
```

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

```python
await client.suggestions("suggest_handler", build=True)
```

> `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`.
If you would like spellcheck suggestion turned on, pass `spellcheck=True` (default is `False`).

```python
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:

```python
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:

```python
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:

```python
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`:

```python
import aiosolr

client = aiosolr.Client(connection_url=connection_url, read_timeout=5, write_timeout=30)
```

You can override the timeouts for a specific request:

```python
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
```

> `aiosolr` uses
> [`asyncio.wait_for`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for)
> internally, so if a timeout occurs the exception raised is `asyncio.TimeoutError`.

## Debugging

To get more information from the Client you can initialize with `debug=True`:

```python
    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](https://docs.aiohttp.org/en/stable/logging.html)) to the `DEBUG` level. This
makes it easier to see the actual network requests going to Solr.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aiosolr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "solr, asyncio, aiohttp, search",
    "author": null,
    "author_email": "Brad Belyeu <bradley.belyeu@youversion.com>",
    "download_url": "https://files.pythonhosted.org/packages/05/09/e9470621bb2d0f74dac3deab5fdb750b07a0a6b96b5c3ba57bbae1552ce2/aiosolr-5.0.1.tar.gz",
    "platform": null,
    "description": "# aiosolr\n\nAsyncIO Python client for Apache Solr\n\n## Requirements\n\nThis project requires Python 3.7+\n\n## Installation\n\nTo install with pip\n\n    pip install aiosolr\n\n## Usage\n\nThe connection to the Solr backend is defined during object initialization. The accepted kwargs to\ninit are `scheme`, `host`, `port`, and `collection`.\n\n> `collection` may optionally be passed at query time\n\n```python\nimport aiosolr\n\nclient = aiosolr.Client(host=localhost, collection=\"example\", port=8983)\n```\n\nAlternatively you may instantiate via passing `connection_url` like:\n\n```python\nimport aiosolr\n\nclient = aiosolr.Client(connection_url=\"http://host:1234/path/to/solr/collection\")\n```\n\nOnce you have your `aiosolr.Client` instance, set up the session:\n\n```python\nawait client.setup()\n```\n\nThere are methods available for querying. You can use Solr's built-in get handler with the `get`\nmethod to retrieve a single document:\n\n```python\nawait client.get(document_id)\n```\n\nYou can use a pre-defined suggestions handler by using the `suggestions` method:\n\n```python\nawait client.suggestions(\"suggest_handler\", query=\"asdf\")\n```\n\nYou can also use the `suggestions` method to build your suggestions:\n\n```python\nawait client.suggestions(\"suggest_handler\", build=True)\n```\n\n> `handler` is a required argument for suggestions unlike for get or query\n\nYou can use the `query` method to query your search handler. The default `handler` used is `select`.\nIf you would like spellcheck suggestion turned on, pass `spellcheck=True` (default is `False`).\n\n```python\nawait client.query(handler=\"my_handler\", query=\"asdf\", spellcheck=True)\n```\n\nIf `spellcheck` is `True` the query method returns a tuple with the first element being an array of\ndocuments and the 2nd element being an array of spellcheck suggestions. Otherwise, the query method\nreturns a simple array of documents.\n\nYou can use the `update` method to access Solr's built-in update handler like:\n\n```python\nawait client.update(my_data)\n```\n\nAt any point that you need to commit data to your collection you can use the `commit` method.\nArguments should be the `handler` (`update` by default) and `soft` as a boolean indicating whether\nit should be a hard or soft commit (defaults to `False`).\n\nThere is one more method you might want to use before querying Solr especially if the query is\ncoming from an untrusted end user. There is a `clean_query` method which can be used to strip out\nunwanted characters. Use it like:\n\n```python\ntrusted_query = aiosolr.clean_query(users_query)\n```\n\nOnce you are finished with the Solr instance, you should call the method `close` to cleanup sessions\nlike:\n\n```python\nawait client.close()\n```\n\n### Timeouts\n\nYou can initialize the client with `read_timeout` and `write_timeout` to limit how long to wait for\nrequests to complete. `read_timeout` applies to `get` and `query` whereas `write_timeout` applies to\n`update`:\n\n```python\nimport aiosolr\n\nclient = aiosolr.Client(connection_url=connection_url, read_timeout=5, write_timeout=30)\n```\n\nYou can override the timeouts for a specific request:\n\n```python\nawait client.get(document_id, read_timeout=1)  # I'm in a hurry\nawait client.update(doc, write_timeout=60)  # this is a large request so we expect it to take a long time\n```\n\n> `aiosolr` uses\n> [`asyncio.wait_for`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for)\n> internally, so if a timeout occurs the exception raised is `asyncio.TimeoutError`.\n\n## Debugging\n\nTo get more information from the Client you can initialize with `debug=True`:\n\n```python\n    import aiosolr\n\n    client = aiosolr.Client(host=localhost, collection=\"example\", port=8983, debug=True)\n```\n\nThis sets the `aiosolr` logger to `DEBUG` level, and also sets the internally used HTTP session\n(provided by [aiohttp](https://docs.aiohttp.org/en/stable/logging.html)) to the `DEBUG` level. This\nmakes it easier to see the actual network requests going to Solr.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Lightweight AsyncIO Python client for Apache Solr",
    "version": "5.0.1",
    "project_urls": {
        "Home": "https://github.com/bbelyeu/aiosolr"
    },
    "split_keywords": [
        "solr",
        " asyncio",
        " aiohttp",
        " search"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "53b015fa76acc7abdaaec9ccd3d935f9f51591d9010610ea7ebe7a80cd8037be",
                "md5": "b6abd666b742a9de7cf232a88617f55c",
                "sha256": "53657200aa1b1b8a6c1239ee827183c751920bacb9871452b92280e555ba313f"
            },
            "downloads": -1,
            "filename": "aiosolr-5.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b6abd666b742a9de7cf232a88617f55c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9434,
            "upload_time": "2024-04-25T02:55:10",
            "upload_time_iso_8601": "2024-04-25T02:55:10.835392Z",
            "url": "https://files.pythonhosted.org/packages/53/b0/15fa76acc7abdaaec9ccd3d935f9f51591d9010610ea7ebe7a80cd8037be/aiosolr-5.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0509e9470621bb2d0f74dac3deab5fdb750b07a0a6b96b5c3ba57bbae1552ce2",
                "md5": "9035a4442987657ef2a4792070b22d52",
                "sha256": "fda8ea28da0924707848654d76cfcdc8e6804a8e62ec8353cb87348a6ead4f8e"
            },
            "downloads": -1,
            "filename": "aiosolr-5.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9035a4442987657ef2a4792070b22d52",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 19073,
            "upload_time": "2024-04-25T02:55:15",
            "upload_time_iso_8601": "2024-04-25T02:55:15.044999Z",
            "url": "https://files.pythonhosted.org/packages/05/09/e9470621bb2d0f74dac3deab5fdb750b07a0a6b96b5c3ba57bbae1552ce2/aiosolr-5.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 02:55:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bbelyeu",
    "github_project": "aiosolr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "aiosolr"
}
        
Elapsed time: 0.25071s