Skip to main content
https://travis-ci.org/7anshuai/pyreds.svg?branch=master

reds is a light-weight Redis Search for Node.js.

pyreds is a Python port of reds.

Installation

pyreds requires a running Redis server. See Redis’s quickstart for installation instructions.

To install pyreds, simply:

$ pip install pyreds

You may need install NLTK Data:

>>> import nltk
>>> nltk.download('stopwords')

Getting Started

The first thing you’ll want to do is create a Search instance, which allow you to pass a key, used for namespacing within Redis so that you may have several searches in the same db.

>>> import pyreds
>>> search = pyreds.create_search('pets')

pyreds acts against arbitrary numeric or string based ids, so you could utilize this library with essentially anything you wish, even combining data stores. The following example just uses a list for our “database”, containing some strings, which we add to pyreds by calling Search#index() padding the body of text and an id of some kind, in this case the index.

>>> strs = []
>>> strs.append('Tobi wants four dollars')
>>> strs.append('Tobi only wants $4')
>>> strs.append('Loki is really fat')
>>> strs.append('Loki, Jane, and Tobi are ferrets')
>>> strs.append('Manny is a cat')
>>> strs.append('Luna is a cat')
>>> strs.append('Mustachio is a cat')
>>> for i, v in enumerate(strs):
...     search.index(v, i)

To perform a query against pyreds simply invoke Search#query() with a string, which return a Query instance. Then invoke Query#end(), which return a list of ids when present, or an empty list otherwise.

>>> ids = search.query('Tobi dollars').end()
>>> print('Search results for "Tobi dollars"'))
>>> for id in ids:
...     print('  - {}'.format(strs[id]))

By default pyreds performs an intersection of the search words. The previous example would yield the following output since only one string contains both “Tobi” and “dollars”:

Search results for "Tobi dollars":
    - Tobi wants four dollars

We can tweak pyreds to perform a union by passing either “union” or “or” to Search#type() between Search#query() and Query#end(), indicating that any of the constants computed may be present for the id to match.

>>> ids = search.query('tobi dollars').type('or').end()
>>> print('Search results for "Tobi dollars"'))
>>> for id in ids:
...     print('  - {}'.format(strs[id]))

The union search would yield the following since three strings contain either “Tobi” or “dollars”:

Search results for "tobi dollars":
    - Tobi wants four dollars
    - Tobi only wants $4
    - Loki, Jane, and Tobi are ferrets

API

>>> search = pyreds.create_search(key)
>>> search.index(text, id)
>>> search.remove(id)
>>> query = search.query(text[, type]) # will return a `Query` instance
>>>
>>> query.between(start, stop)
>>> query.type(type)
>>> query.end()

LICENSE

The MIT License

Metadata

Release files for pyreds 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyreds 0.1.4
File Size Uploaded
pyreds-0.1.4.tar.gz 9.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyreds 0.1.4
File Interpreter ABI Platform
pyreds-0.1.4-py3-none-any.whl Python 3 none any Details
pyreds-0.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.4 kB

Release files / pyreds-0.1.4.tar.gz

Download URL pyreds-0.1.4.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
91551c52709c510e7732bfa91680c309c681f3cb4772a5de4803b4fa21496d31
BLAKE2b-256 checksum
How to use checksums
7e142981e18ce6965521f39cae5c5e7bedd4f8b29bbf6779de3c02f6b857784a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.6

Release files / pyreds-0.1.4-py3-none-any.whl

Download URL pyreds-0.1.4-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3982cc2a9f2dc1272d552af5e6592dfe85494d364d251fe1ee4397bae782b3ae
BLAKE2b-256 checksum
How to use checksums
0994229947473d904434fc7983473a81ace5c1757449b1fc64370ff1eb09ef3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.6

Release files / pyreds-0.1.4-py2.py3-none-any.whl

Download URL pyreds-0.1.4-py2.py3-none-any.whl
Size 9.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
76c867dd42e9d2651bdb425d8d8711d6d214f1c591437b0ab776406ac4aa7eb9
BLAKE2b-256 checksum
How to use checksums
44a1b772ef9791c031e9c9873f5a8609a10d127ba3c3e19c0a84b0abeae4854a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.1.4 This release

3 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page