Can I use Python to index URLs and Documents?

Yes. Below is a sample Python script that can be used to index URLs or documents (filesystem can be specified only when using the same server as SearchBlox).

Refer to our developer document page on REST API for indexing documents for more information on parameters passed

def index_document(post_url: str, api_key: str, collection_name: str):
Index a document by sending a POST request to SearchBlox API.

Developer Documentation Reference:

post_url (str): SearchBlox API URL to Index Documents
api_key (str): SearchBlox API Key
collection_name (str): Name of the collection

Response received from SearchBlox (<Requests Response>)
payload = {
"apikey": api_key,
"document": {
"colname": collection_name,
"url": "",
"uid": "",
"location": "",
"alpha": "SearchBlox Product Features",
"size": "44244",
"title": "SearchBlox Product Features",
"keywords": "SearchBlox, Solr, Lucene, Faceted Search",
"description": "SearchBlox Content Search Software",
"content": "content",
"lastmodified": "14 January 2020 06:19:42 GMT",
"contenttype": "HTML",
"meta": {
"location": "San Francisco",
"temp": "23",
"weather": "sunny"

# Make the POST request to SearchBlox API by supplying JSON
resp =, json=payload)

# Returning the response
return resp

if __name__ == '__main__':
# SearchBlox API Key, API URL to Index Documents and Collection Name
posturl = "http://localhost:8080/searchblox/rest/v2/api/add"
collection = "HTTPCollection"

# Call the function and pass post url, api key and collection name
response = index_document(
post_url=posturl, api_key=apikey, collection_name=collection

if response.status_code != 200:
print("Please check the JSON Payload. Here's the error message: {}"
except Exception:
print("Please check the JSON Payload")

To learn more about SearchBlox please visit our developer document site

Have more questions? Submit a request