Skip to main content

A small asynchronous Solr client

Project description

small-asc

A small, asynchronous Solr client for Python, built as a modern replacement for PySolr.

small-asc uses HTTPX (via pyreqwest) and orjson for fast, asynchronous communication with Apache Solr. It exclusively uses the Solr JSON Request API for queries and updates.

Requirements

  • Python >= 3.14

Installation

Install from PyPI using your preferred package manager:

pip install small-asc

Or with uv:

uv add small-asc

Basic Usage

Connecting to Solr

from small_asc import client

solr = client.Solr("http://localhost:8983/solr/mycollection")

Searching

The search() method accepts a dictionary conforming to the Solr JSON Request API:

query = {
    "query": "title:sonata",
    "fields": ["id", "title", "creator"],
    "limit": 10,
    "offset": 0,
}

results = await solr.search(query)

# Access result documents
for doc in results.docs:
    print(doc["title"])

# Access metadata
print(f"Total hits: {results.hits}")
print(f"Query time: {results.qtime}ms")

Cursor-based Pagination

For retrieving large result sets, enable cursor-based iteration to automatically fetch additional pages:

query = {
    "query": "*:*",
    "fields": ["id"],
    "sort": "id asc",
}

async for doc in await solr.search(query, cursor=True):
    print(doc["id"])

Adding Documents

docs = [
    {"id": "1", "title": "Example Document"},
    {"id": "2", "title": "Another Document"},
]

response = await solr.add(docs)

Retrieving Documents by ID

doc = await solr.get("record-123")
print(doc)

Deleting Documents

# Delete by query
response = await solr.delete("type:draft")

Term Suggestions

suggestions = await solr.term_suggest({
    "query": "Mozar",
    "fields": ["creator_name_s"],
})

Query Parsing

small-asc includes a Lucene query parser that validates and processes Solr/Lucene-style queries before sending them to the server. This helps catch syntax errors early and supports field name mapping.

Basic Validation

from small_asc.query import validate_query

if validate_query("title:(foo AND bar)"):
    print("Valid query")

Parsing with Field Replacements

Map frontend field names to internal Solr field names:

from small_asc.query import parse_with_field_replacements

field_map = {
    "creator": "creator_name_s",
    "shelfmark": "shelfmark_sm",
}

parsed = parse_with_field_replacements(
    'creator:Mozart AND shelfmark:"MLHs"',
    fields=field_map
)
# Returns: 'creator_name_s:Mozart AND shelfmark_sm:"MLHs"'

Supported Query Syntax

  • Terms and phrases: foo, "hello world"
  • Fielded queries: title:foo, creator:"Bach, J.S."
  • Boolean operators: AND, OR, NOT (treated as terms in ungrouped contexts)
  • Boolean groups: (foo AND bar), (a OR b NOT c)
  • Required/prohibited: +must_have, -exclude
  • Wildcards: foo*, foo?
  • Fuzziness: foo~2, "hello"~0.5
  • Proximity: "hello world"~10
  • Boosting: foo^2.0, "phrase"^3.0
  • Ranges: [10 TO 20], {A TO Z}, [* TO 20]
  • Unicode: Supports full Unicode in terms and phrases

Development

Running Tests

The test suite uses pytest:

uv run pytest tests/

Building

Build distributions with uv:

uv build

This produces both a source distribution (.tar.gz) and a wheel (.whl) in the dist/ directory.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

small_asc-1.0.2.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

small_asc-1.0.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file small_asc-1.0.2.tar.gz.

File metadata

  • Download URL: small_asc-1.0.2.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for small_asc-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b29fb3ecaecbb5fe98b0a702ab345af681b3c5f32118a9710a15045c2fc64735
MD5 020c9e09436c423482207ec7c73f36fa
BLAKE2b-256 39087fd3cd85caf80e7e001610d450408a7a1570b2857d9fb00b85f14b7d76f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for small_asc-1.0.2.tar.gz:

Publisher: publish.yml on rism-digital/small-asc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file small_asc-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: small_asc-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for small_asc-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fef2a4338a4db3106b0896d3951986cb32bb2d39680b6bf45419cb953070724f
MD5 e84a2a64877f9230e34926716f963ba9
BLAKE2b-256 a22b6aa2c17f815c1ba455ba7e564c3ba048c39419ba21141c3e1f4fc1c88f46

See more details on using hashes here.

Provenance

The following attestation bundles were made for small_asc-1.0.2-py3-none-any.whl:

Publisher: publish.yml on rism-digital/small-asc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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