Files.com Python Client

1.6.348 · active · verified Thu Apr 16

The `files-com` Python client provides official Python bindings for interacting with the Files.com API. It enables developers to programmatically manage files, folders, users, permissions, and other resources on the Files.com platform. As of version `1.6.348`, it offers direct access to API endpoints through a convenient object-oriented interface and is actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure the Files.com Python client using environment variables for API key and base URL, then perform basic operations like listing users and creating/deleting a folder. It includes basic error handling for common API exceptions.

import files_com
import os

# Configure API Key and Base URL (highly recommended to use environment variables)
files_com.api_key = os.environ.get('FILESCOM_API_KEY', '') # Replace '' with your actual API key for local testing
files_com.base_url = os.environ.get('FILESCOM_BASE_URL', 'https://app.files.com') # Replace with your custom domain if applicable

if not files_com.api_key:
    print("Error: FILESCOM_API_KEY environment variable not set or API key not provided.")
    exit(1)

try:
    # Example: List users
    print("Listing users...")
    users = files_com.User.list(per_page=10) # Fetch up to 10 users
    if users:
        for user in users:
            print(f"  User ID: {user.id}, Username: {user.username}, Email: {user.email}")
    else:
        print("  No users found.")

    # Example: Create a new folder (adjust name as needed)
    print("\nCreating a new folder...")
    try:
        new_folder = files_com.Folder.create(path='/my_test_folder', name='MyNewFolder123')
        print(f"  Folder '{new_folder.path}' created successfully (ID: {new_folder.id}).")
        
        # Example: Delete the created folder
        print(f"\nDeleting folder '{new_folder.path}'...")
        files_com.Folder.delete(path=new_folder.path)
        print(f"  Folder '{new_folder.path}' deleted successfully.")
    except files_com.exceptions.ApiError as e:
        print(f"  Failed to create/delete folder: {e.message}")

except files_com.exceptions.UnauthorizedException as e:
    print(f"Authentication failed: {e.message}. Check your API key and base URL.")
except files_com.exceptions.NotFoundException as e:
    print(f"Resource not found: {e.message}. Check paths and IDs.")
except files_com.exceptions.ApiError as e:
    print(f"An API error occurred: {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →