or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

admin-api.mdconfiguration.mddjango-integration.mdexceptions.mdindex.mdprovisioning-api.mdsearch-api.mdtransformations.mdupload-api.md
tile.json

tessl/pypi-cloudinary

Python and Django SDK for Cloudinary, a cloud-based image and video management service with comprehensive transformation, optimization, and delivery capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/cloudinary@1.44.x

To install, run

npx @tessl/cli install tessl/pypi-cloudinary@1.44.0

index.mddocs/

Cloudinary Python SDK

A comprehensive Python and Django SDK for Cloudinary, a cloud-based image and video management service. The SDK provides complete integration for uploading, transforming, optimizing, and delivering media assets with extensive transformation capabilities, automatic optimization, and seamless Django integration.

Package Information

  • Package Name: cloudinary
  • Language: Python
  • Installation: pip install cloudinary
  • Repository: https://github.com/cloudinary/pycloudinary

Core Imports

import cloudinary

Common for configuration and basic usage:

from cloudinary import config, CloudinaryImage, CloudinaryVideo

Common for uploading media:

from cloudinary import uploader

Common for Admin API operations:

from cloudinary import api

Basic Usage

import cloudinary
from cloudinary import uploader
from cloudinary.utils import cloudinary_url

# Configure your account
cloudinary.config(
    cloud_name="your_cloud_name",
    api_key="your_api_key",
    api_secret="your_api_secret"
)

# Upload an image
upload_result = uploader.upload("path/to/image.jpg")
public_id = upload_result['public_id']

# Generate a transformation URL
url, options = cloudinary_url(
    public_id,
    width=300,
    height=200,
    crop="fill",
    format="webp"
)

# Create CloudinaryImage object for advanced operations
image = CloudinaryImage(public_id)
transformed_url = image.build_url(
    width=400,
    height=300,
    crop="scale",
    quality="auto"
)

Architecture

The SDK is organized around several key components:

  • Configuration: Global and account-specific settings management
  • Resource Classes: CloudinaryImage and CloudinaryVideo for media manipulation
  • Upload API: Functions for uploading media files with preprocessing
  • Admin API: Complete resource management and account administration
  • Transformation Engine: URL-based image and video transformation system
  • Django Integration: Models, forms, and template tags for web applications
  • Caching System: Performance optimization for repeated operations
  • Search API: Advanced asset discovery and filtering

Capabilities

Configuration and Setup

Global configuration management for Cloudinary account credentials, default transformation parameters, and SDK behavior settings.

def config(**keywords):
    """Configure Cloudinary account settings and defaults.
    
    Args:
        cloud_name (str): Your Cloudinary cloud name
        api_key (str): Your API key
        api_secret (str): Your API secret
        secure (bool): Use HTTPS URLs (default: True)
        cdn_subdomain (bool): Use multiple CDN subdomains
        **kwargs: Additional configuration options
    
    Returns:
        Config: Configuration object
    """

def reset_config():
    """Reset configuration to defaults."""

class Config:
    """Configuration object for Cloudinary settings."""

class CloudinaryResource:
    """Base class for Cloudinary media resources."""

class CloudinaryImage(CloudinaryResource):
    """Image-specific resource class with transformation capabilities."""

class CloudinaryVideo(CloudinaryResource):
    """Video-specific resource class with transformation capabilities."""

Configuration and Setup

Upload API

Comprehensive media upload functionality with preprocessing options, format conversion, and metadata extraction for images, videos, and raw files.

def upload(file, **options):
    """Upload a file to Cloudinary.
    
    Args:
        file: File path, file object, or URL to upload
        public_id (str, optional): Custom public ID
        folder (str, optional): Folder to store the asset
        use_filename (bool, optional): Use original filename
        unique_filename (bool, optional): Add unique suffix
        overwrite (bool, optional): Overwrite existing asset
        **options: Additional upload parameters
    
    Returns:
        dict: Upload result with public_id, url, secure_url, etc.
    """

def destroy(public_id, **options):
    """Delete an uploaded asset.
    
    Args:
        public_id (str): Public ID of asset to delete
        **options: Additional deletion options
    
    Returns:
        dict: Deletion result
    """

def rename(from_public_id, to_public_id, **options):
    """Rename an uploaded asset.
    
    Args:
        from_public_id (str): Current public ID
        to_public_id (str): New public ID
        **options: Additional options
    
    Returns:
        dict: Rename result
    """

Upload API

Admin API

Complete resource management including asset discovery, metadata operations, transformation management, and account administration.

def resources(**options):
    """List uploaded resources with filtering options.
    
    Args:
        resource_type (str, optional): Filter by resource type
        type (str, optional): Filter by delivery type
        prefix (str, optional): Filter by public_id prefix
        max_results (int, optional): Maximum results to return
        **options: Additional filtering options
    
    Returns:
        dict: List of resources with metadata
    """

def resource(public_id, **options):
    """Get details of a specific resource.
    
    Args:
        public_id (str): Public ID of the resource
        **options: Additional options
    
    Returns:
        dict: Resource details and metadata
    """

def delete_resources(public_ids, **options):
    """Delete multiple resources.
    
    Args:
        public_ids (list): List of public IDs to delete
        **options: Additional deletion options
    
    Returns:
        dict: Deletion results
    """

Admin API

URL Generation and Transformations

Powerful URL-based transformation system for images and videos with automatic optimization, responsive delivery, and format conversion.

def cloudinary_url(public_id, **options):
    """Generate Cloudinary URL with transformations.
    
    Args:
        public_id (str): Public ID of the resource
        width (int, optional): Target width
        height (int, optional): Target height
        crop (str, optional): Crop mode ('fill', 'scale', 'fit', etc.)
        quality (str|int, optional): Quality setting or 'auto'
        format (str, optional): Output format or 'auto'
        secure (bool, optional): Use HTTPS
        **options: Additional transformation parameters
    
    Returns:
        tuple: (url, options_dict)
    """

def cloudinary_tag(public_id, **options):
    """Generate HTML img tag with Cloudinary URL.
    
    Args:
        public_id (str): Public ID of the resource
        **options: Transformation and HTML attributes
    
    Returns:
        str: HTML img tag
    """

URL Generation and Transformations

Search API

Advanced asset discovery with filtering, sorting, and aggregation capabilities for finding specific resources in your Cloudinary account.

class Search:
    """Search for resources using various criteria."""
    
    def expression(self, value):
        """Set search expression."""
    
    def max_results(self, value):
        """Set maximum results to return."""
    
    def next_cursor(self, value):
        """Set cursor for pagination."""
    
    def sort_by(self, field, direction="desc"):
        """Add sort criteria."""
    
    def aggregate(self, value):
        """Add aggregation."""
    
    def with_field(self, value):
        """Include additional fields in results."""
    
    def execute(self, **options):
        """Execute the search query."""

Search API

Provisioning API

Complete account provisioning and management including sub-account creation, user management, access key generation, and multi-tenant environment setup.

def create_sub_account(name, **options):
    """Create a new sub-account for multi-tenant environments.
    
    Args:
        name (str): Name for the sub-account
        **options: Additional sub-account configuration
    
    Returns:
        dict: Sub-account details with cloud_name and credentials
    """

def create_user(name, email, role, **options):
    """Create a new user with specified permissions.
    
    Args:
        name (str): User's display name
        email (str): User's email address  
        role (str): User role (Admin, Developer, Billing, etc.)
        **options: Additional user configuration
    
    Returns:
        dict: User details with ID and access credentials
    """

def generate_access_key(name, **options):
    """Generate API access keys for programmatic access.
    
    Args:
        name (str): Descriptive name for the access key
        **options: Key configuration and permissions
    
    Returns:
        dict: Access key details with api_key and api_secret
    """

Provisioning API

Django Integration

Complete Django framework integration including model fields, form widgets, template tags, and admin interface components.

class CloudinaryField(models.Field):
    """Django model field for Cloudinary resources."""

class CloudinaryInput(forms.TextInput):
    """Django form widget for Cloudinary file input."""

class CloudinaryFileField(forms.FileField):
    """Django form field for Cloudinary file uploads."""

def cloudinary_url():
    """Django template tag for generating Cloudinary URLs."""

def cloudinary_tag():
    """Django template tag for generating Cloudinary image tags."""

Django Integration

Exception Handling

Comprehensive exception hierarchy for handling API errors, authentication issues, and operational failures.

class Error(Exception):
    """Base exception class for Cloudinary errors."""

class NotFound(Error):
    """Resource not found exception."""

class NotAllowed(Error):
    """Operation not allowed exception."""

class BadRequest(Error):
    """Bad request exception."""

class AuthorizationRequired(Error):
    """Authorization required exception."""

Exception Handling