Skip to main content

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

Metadata

Release files for small-asc 1.0.3

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

Source distribution (sdist)

Source distribution for small-asc 1.0.3
File Size Uploaded
small_asc-1.0.3.tar.gz 35.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for small-asc 1.0.3
File Interpreter ABI Platform
small_asc-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 45.7 kB

Release files / small_asc-1.0.3.tar.gz

Download URL small_asc-1.0.3.tar.gz
Size 35.7 kB
Tags Source
SHA-256 checksum
How to use checksums
beb2524a4df233546a59c222c991a1d80d00ac79bf72c6c9569bccb17e0a8777
BLAKE2b-256 checksum
How to use checksums
eaa1f95948de17c860bb01982c76f6bc9c8184f0209a0b1765cec33b6de2eeb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release files / small_asc-1.0.3-py3-none-any.whl

Download URL small_asc-1.0.3-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7002e99b1299378d917abcfcd5694af6704652819e102a8ba98c631294b9dcbb
BLAKE2b-256 checksum
How to use checksums
2fc99bf66f55bb6c4fcb03d958c43292c0fca039ced43dd841e6b8d75b8afb10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.36.0

2 release files

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