Official Python SDK for interacting with ContentZen headless CMS.
Project description
ContentZen Python SDK
Official Python SDK for interacting with ContentZen headless CMS.
Features
- Access public and private ContentZen API endpoints
- Full CRUD for documents, collections, media, and webhooks
- Automatic API token authentication
- Custom exceptions for robust error handling
- Simple, Pythonic interface
Installation
pip install contentzen # (when published)
Authentication
Some endpoints require an API token. You can obtain your API token after registering at contentzen.io.
Usage
Public Endpoints (No Auth Required)
from contentzen import ContentZenClient
client = ContentZenClient()
public_docs = client.get_public_documents(collection_uuid="your-collection-uuid")
public_doc = client.get_public_document(collection_uuid="your-collection-uuid", document_uuid="your-document-uuid")
Private Endpoints (API Token Required)
from contentzen import ContentZenClient
client = ContentZenClient(api_token="your_api_token")
Documents
docs = client.get_documents(collection_uuid="your-collection-uuid")
doc = client.get_document(collection_uuid="your-collection-uuid", document_uuid="your-document-uuid")
new_doc = client.create_document(collection_uuid="your-collection-uuid", payload={"title": "New Post", "content": "..."})
updated_doc = client.update_document(collection_uuid="your-collection-uuid", document_uuid="your-document-uuid", payload={"title": "Updated"})
client.delete_document(collection_uuid="your-collection-uuid", document_uuid="your-document-uuid")
Collections
collections = client.get_collections()
collection = client.get_collection(collection_uuid="your-collection-uuid")
created = client.create_collection(
name="products",
display_name="Products",
description="Product catalog",
is_public=False,
fields=[{"name": "title", "type": "string", "display_name": "Title", "required": True}]
)
updated = client.update_collection(
collection_uuid="your-collection-uuid",
display_name="Updated Products",
description="Updated description",
is_public=True,
fields=[{"name": "title", "type": "string", "display_name": "Title", "required": True}]
)
client.delete_collection(collection_uuid="your-collection-uuid")
schema = client.get_collection_schema(collection_uuid="your-collection-uuid")
fields = client.get_collection_fields(collection_uuid="your-collection-uuid")
field_types = client.get_field_types()
Media
media_list = client.list_media()
media = client.get_media_file(media_uuid="your-media-uuid")
client.upload_media(file_path="/path/to/file.jpg")
client.update_media(media_uuid="your-media-uuid", alt_text="New alt text")
client.delete_media(media_uuid="your-media-uuid")
client.download_media(media_uuid="your-media-uuid", dest_path="/tmp/file.jpg")
Webhooks
webhooks = client.list_webhooks()
created = client.create_webhook(
name="My Webhook",
url_="https://example.com/webhook",
events=["document.created", "document.updated"]
)
updated = client.update_webhook(
webhook_uuid="your-webhook-uuid",
name="Updated Webhook",
url_="https://example.com/webhook",
events=["document.created", "document.updated", "document.deleted"]
)
client.delete_webhook(webhook_uuid="your-webhook-uuid")
Error Handling
All methods raise custom exceptions on errors:
AuthenticationError: Invalid or missing API tokenNotFoundError: Resource not found (404)APIError: Other API errorsContentZenError: Base exception
Example:
from contentzen import ContentZenClient
from contentzen.exceptions import AuthenticationError, NotFoundError, APIError
client = ContentZenClient(api_token="invalid")
try:
docs = client.get_documents(collection_uuid="...")
except AuthenticationError:
print("Invalid API token!")
except NotFoundError:
print("Resource not found!")
except APIError as e:
print(f"API error: {e}")
Troubleshooting
- Ensure your API token is valid and has the correct permissions
- Check that UUIDs for collections, documents, media, and webhooks are correct
- For file uploads/downloads, verify file paths and permissions
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
contentzen-0.1.0.tar.gz
(5.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contentzen-0.1.0.tar.gz.
File metadata
- Download URL: contentzen-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7e06d7bb8ed8d2aa351f7d07c8155d315a23bf80235cc3857ce9feec4037015
|
|
| MD5 |
1722e8a882412da80572a39460a2ca77
|
|
| BLAKE2b-256 |
3b1a50f77c41edcfa705537d6abfb61688528b5862c976fa07e4a0a73b05c3a5
|
File details
Details for the file contentzen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: contentzen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5d613df733de7881111e7e98af391d58cfca771838fa5793e633342996c0a5c
|
|
| MD5 |
2b65f46d50d8aca459229618e4b83856
|
|
| BLAKE2b-256 |
4fe29458f4b9a3b816c026cd26160f3d86ee231b0424b8b39f6097501bc391dc
|