Poisk implements a thin veneer of convenience over familiar search functions. It can be used for:
- regular expression searches;
- jq- or JMESPath-style searches in lists and dicts;
- XPath queries over ElementTrees.
one and many
At the core of Poisk is the idea that you'd rather raise an exception than extract the wrong data. We want to check that our expectations hold. If we expect our search to return matches, it should not return an empty list. If we expect a single matching element, there shouldn't be two.
The search functions are grouped into two modules, called one and many. The
search functions under one expect to find a single matching value, which they
return. They raise NotFound if no results are found, and ManyFound if more
than one match is found.
Here is an example using one.re, which performs regular expression searches:
>>> from poisk import one
>>> one.re(r'H\w+', 'Hello world!')
'Hello'
>>> one.re(r'H\w+', 'Greetings, world!')
Traceback (most recent call last):
...
poisk.exceptions.NotFound: 'H\\w+' in 'Greetings, world!'
>>> one.re(r'H\w+', 'Ho Ho Ho, world!')
Traceback (most recent call last):
...
poisk.exceptions.ManyFound: 'H\\w+' in 'Ho Ho Ho, world!'
The corresponding functions under many expect one or more results, which they
return as a list. They raise NotFound if no matches are found:
>>> from poisk import many
>>> many.re(r'\w+', 'Hello!')
['Hello']
>>> many.re(r'\w+', 'Hello world!')
['Hello', 'world']
>>> many.re(r'\d+', 'Hello world!')
Traceback (most recent call last):
...
poisk.exceptions.NotFound: '\\d+' in 'Hello world!'
Supported search functions
The previous two examples use one.re and many.re to perform regular
expression searches, using the standard
re module.
Also available are functions for xpath search over ElementTrees using lxml.etree:
>>> import lxml.etree as ET
>>> from poisk import many, one
>>> document = ET.HTML('''
... <div>
... <p id="p1">First paragraph</p>
... <p id="p2">Second paragraph</p>
... </div>
... ''')
>>> one.etree('p[@id="p1"]/text()', document)
'First paragraph'
>>> many.etree('p/text()', document)
['First paragraph', 'Second paragraph']
The same one.etree and many.etree functions accept CSS selectors (via
cssselect):
>>> one.etree('p#p1', document).text
'First paragraph'
The one.pods and many.pods functions allow searches using Plain Old Data
Structures (dicts and lists) using a jq- or JMESPath-style query language:
>>> data = {
... "payload": {
... "total": 3,
... "results": [
... {"id": 1},
... {"id": 2},
... {"id": 3},
... ],
... },
... }
>>> one.pods('payload.total', data)
3
>>> many.pods('payload.results[].id', data)
[1, 2, 3]
The test/ directory contains many more examples of the sort functionality that Poisk offers.
Metadata
Release files for poisk 1.0.3
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 | |
|---|---|---|---|---|
| poisk-1.0.3.tar.gz | 13.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poisk-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.9 kB
Release files / poisk-1.0.3.tar.gz
| Download URL | poisk-1.0.3.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba3f9469f0f535787b5a8dfd74594e75a839d9eb65c19b4bea18dd043ace5335
|
|
BLAKE2b-256 checksum How to use checksums |
d046d193ab8fdca5528974db1db3ee1363473c69abd794ee9b5c3841e36b8e65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / poisk-1.0.3-py3-none-any.whl
| Download URL | poisk-1.0.3-py3-none-any.whl |
|---|---|
| Size | 15.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
600940c5bd4e55da3a7fc2e4967904d9ca3be5026af966f343c8324535823651
|
|
BLAKE2b-256 checksum How to use checksums |
7ca7bfc333cf9b53dbe574bb1edd4fdefc9c423d77bc6c54df7010c54ef6e3db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for poisk 1.0.3
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.