{"id":6817,"library":"pysolr","title":"PySolr","description":"PySolr is a lightweight Python client for Apache Solr, providing an interface for querying, indexing, and managing data in Solr. It is actively maintained with version 3.11.0 being the latest stable release, and typically sees 1-3 major releases per year, though the cadence can be irregular.","status":"active","version":"3.11.0","language":"en","source_language":"en","source_url":"https://github.com/django-haystack/pysolr/","tags":["solr","apache solr","search","client","full-text search"],"install":[{"cmd":"pip install pysolr","lang":"bash","label":"Install PySolr"}],"dependencies":[{"reason":"Required for HTTP communication with Solr.","package":"requests","optional":false},{"reason":"Optional dependency for SolrCloud awareness and ZooKeeper integration.","package":"kazoo","optional":true},{"reason":"Optional dependency for enhanced JSON support, particularly in older versions or specific use cases.","package":"simplejson","optional":true}],"imports":[{"note":"The primary class for interacting with a Solr instance.","symbol":"Solr","correct":"import pysolr\nsolr = pysolr.Solr('http://localhost:8983/solr/')"}],"quickstart":{"code":"import os\nimport pysolr\n\nsolr_url = os.environ.get('SOLR_URL', 'http://localhost:8983/solr/')\n\ntry:\n    # Connect to Solr with explicit commit behavior\n    solr = pysolr.Solr(solr_url, always_commit=True, timeout=10)\n\n    # Do a health check\n    solr.ping()\n    print(f\"Successfully connected to Solr at {solr_url}\")\n\n    # Index some data\n    docs_to_add = [\n        {\"id\": \"doc_1\", \"title\": \"The Quick Brown Fox\"},\n        {\"id\": \"doc_2\", \"title\": \"Jumps Over The Lazy Dog\"},\n    ]\n    solr.add(docs_to_add)\n    print(\"Added documents.\")\n\n    # Search for data\n    results = solr.search('fox')\n\n    print(f\"Found {len(results)} result(s) for 'fox':\")\n    for result in results:\n        print(f\"  - ID: {result['id']}, Title: {result['title']}\")\n\n    # Delete a document\n    solr.delete(id='doc_1')\n    print(\"Deleted doc_1.\")\n\n    # Search again to confirm deletion\n    results_after_delete = solr.search('fox')\n    print(f\"Found {len(results_after_delete)} result(s) for 'fox' after deletion.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to connect to a Solr instance, index documents, perform a search, and delete documents. It uses `os.environ.get` for the Solr URL to support flexible deployment, defaulting to a local Solr instance. Note the use of `always_commit=True` due to a significant change in default behavior in recent versions."},"warnings":[{"fix":"Ensure your Python environment is running version 3.10 or newer before upgrading to recent PySolr versions.","message":"PySolr has progressively dropped support for older Python versions. As of v3.9.0, Python 3.4 support was dropped. With v3.11.0, support for Python 3.9 and below has been explicitly removed. PySolr now strictly requires Python >=3.10.","severity":"breaking","affected_versions":">=3.9.0 (for Python 3.4), >=3.11.0 (for Python <=3.9)"},{"fix":"To maintain immediate indexing, initialize the Solr client with `pysolr.Solr(..., always_commit=True)`, or explicitly pass `commit=True` to individual `add()` or `delete()` calls (e.g., `solr.add(docs, commit=True)`). Alternatively, configure Solr's `autoCommit` or `commitWithin` policies.","message":"The default commit behavior for add/delete operations changed significantly in v3.8.1. Previously, these operations would implicitly commit changes to Solr. From v3.8.1 onwards, `always_commit` defaults to `False` for performance. This means changes are buffered and not immediately searchable unless explicitly committed.","severity":"breaking","affected_versions":">=3.8.1"},{"fix":"Review your Solr configuration and PySolr usage to ensure you are leveraging the JSON interface for optimal performance, especially for bulk indexing. PySolr handles JSON conversion automatically when passing Python dicts/lists, but awareness of the underlying mechanism is beneficial.","message":"PySolr v3.9.0 introduced a JSON interface which can offer significantly faster data loading (up to 15-20 times faster) compared to the older XML-based conversion. Users may inadvertently stick to less performant methods.","severity":"gotcha","affected_versions":">=3.9.0"},{"fix":"Carefully verify the Solr core URL and handler names, especially when moving between different Solr configurations or custom handlers. Consult your Solr `solrconfig.xml` for exact handler path specifications.","message":"When using custom Solr request handlers (often with `use_qt_param=True`), the handler name specified in the PySolr URL must precisely match the configuration in `solrconfig.xml`, including any leading slashes (e.g., `/update`). If `use_qt_param` is `False` (the default), leading/trailing slashes can be omitted.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all development and deployment environments are standardized on Python 3.10 or newer. Update any dependency management or CI/CD configurations that might implicitly assume Python 2 compatibility.","message":"As part of the shift to Python 3, PySolr v3.11.0 explicitly removed the Python 2 tag from its distribution metadata. While Python 2 compatibility was waning in earlier 3.x releases, this action definitively signals the end of any remaining support. Attempting to use newer PySolr versions with Python 2 tooling or environments may lead to installation failures or runtime errors.","severity":"deprecated","affected_versions":">=3.11.0"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}