Update specific corpus fields without affecting others. This is the recommended approach for incremental changes like toggling visibility, updating descriptions, or modifying individual settings.
Recommended for most updates: Only send the fields you want to change. All other fields remain unchanged.
Perfect for single-field updates like toggling is_published or updating descriptions without risk of resetting other values.
The most common PATCH operation - make a corpus public or private:
Copy
# Publish a corpusrequests.patch( f"{base_url}/api/corpora/{corpus_id}/", headers=headers, json={"is_published": True})# Unpublish for maintenancerequests.patch( f"{base_url}/api/corpora/{corpus_id}/", headers=headers, json={"is_published": False})
Use case: Temporarily hiding a corpus during updates or making it available to other users.
Update Description Only
Modify the description without affecting any other fields:
Copy
requests.patch( f"{base_url}/api/corpora/{corpus_id}/", headers=headers, json={"description": "Updated with Q4 2024 product documentation"})
Safe: No risk of accidentally changing name, visibility, or index type.
Batch Status Updates
Update multiple corpora efficiently:
Copy
corpus_ids = ["id1", "id2", "id3"]# Publish all corporafor corpus_id in corpus_ids: try: requests.patch( f"{base_url}/api/corpora/{corpus_id}/", headers=headers, json={"is_published": True} ) print(f"Published {corpus_id}") except Exception as e: print(f"Failed to publish {corpus_id}: {e}")
Safe Index Type Migration
Change index strategy while preserving all other settings:
Copy
# Get current corpuscorpus = requests.get( f"{base_url}/api/corpora/{corpus_id}/", headers=headers).json()print(f"Current index type: {corpus['index_type']}")# Update only the index typeupdated = requests.patch( f"{base_url}/api/corpora/{corpus_id}/", headers=headers, json={"index_type": "SMI"} # Switch to Summary Index).json()# Wait for re-indexingif updated["indexing_status"] == "PRS": print("Re-indexing started. Monitor status...")
Note: All other fields (name, description, visibility) remain unchanged.
Conditional Updates
Update only if conditions are met:
Copy
# Get current statecorpus = requests.get( f"{base_url}/api/corpora/{corpus_id}/", headers=headers).json()# Only publish if indexing is completeif corpus["indexing_status"] == "IND": requests.patch( f"{base_url}/api/corpora/{corpus_id}/", headers=headers, json={"is_published": True} ) print("Corpus published")else: print(f"Corpus not ready (status: {corpus['indexing_status']})")
Validation: Name uniqueness and index_type enum validation still apply. Invalid values return 400 Bad Request.
Best Practice: Always use PATCH for single-field updates rather than PUT to avoid accidentally resetting fields to defaults.