Python Alfresco API Client

1.1.5 · active · verified Thu Apr 16

Python Client for all Alfresco Content Services REST APIs, built with Pydantic v2 models for robust data validation and serialization, and offering event support. It provides comprehensive coverage of Alfresco's API endpoints through dedicated subclients. The current version is 1.1.5, with frequent updates incorporating new API features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Alfresco client using environment variables for credentials, then fetches the 'Company Home' node by path and creates a new folder within it. Ensure your Alfresco instance is running and accessible.

import os
from alfresco_api.client import AlfrescoClient
from alfresco_api.model.nodes import NodeBodyCreate

# Configure Alfresco connection via environment variables
ALFRESCO_HOST = os.environ.get('ALFRESCO_HOST', 'http://localhost:8080')
ALFRESCO_USERNAME = os.environ.get('ALFRESCO_USERNAME', 'admin')
ALFRESCO_PASSWORD = os.environ.get('ALFRESCO_PASSWORD', 'admin')

# Initialize the client
try:
    client = AlfrescoClient(
        host=ALFRESCO_HOST,
        username=ALFRESCO_USERNAME,
        password=ALFRESCO_PASSWORD
    )

    # Example: Get the 'Company Home' node by its path (v1.1.5+ feature)
    nodes_api = client.nodes
    company_home_node = nodes_api.get_node_by_path(relative_path='/Company Home')
    print(f"Successfully connected. Company Home Node ID: {company_home_node.entry.id}")

    # Example: Create a new folder
    new_folder_name = 'MyTestFolder'
    folder_create_body = NodeBodyCreate(
        name=new_folder_name,
        node_type='cm:folder',
        properties={'cm:title': 'My Test Folder via Python API'}
    )
    created_folder = nodes_api.create_node(
        node_id=company_home_node.entry.id,
        node_body_create=folder_create_body
    )
    print(f"Created folder '{new_folder_name}' with ID: {created_folder.entry.id}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →