Registry / http-networking / cloudinary

cloudinary

JSON →
library1.44.1pypypi✓ verified 35d ago

The Cloudinary Python SDK provides a comprehensive platform for managing digital media, including image and video upload, transformation, optimization, and delivery capabilities. It supports general Python applications as well as the Django framework. Currently at version 1.44.1, the library is actively maintained with frequent updates, typically focusing on new feature additions, API enhancements, and security improvements.

http-networkingweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

import cloudinary
import cloudinary.uploader
import cloudinary.api

Used for simplified image URL generation.

from cloudinary import CloudinaryImage

Django-specific model field for storing Cloudinary asset URLs.

from cloudinary.models import CloudinaryField

Django-specific form field for uploading files to Cloudinary.

from cloudinary.forms import CloudinaryFileField

This quickstart demonstrates how to configure the Cloudinary Python SDK, upload an image from a remote URL, generate a transformed URL, and retrieve asset details using the Admin API. It emphasizes using environment variables (especially `CLOUDINARY_URL`) for secure configuration. For local development, `python-dotenv` is used to load these variables from a `.env` file.

import os from dotenv import load_dotenv import cloudinary import cloudinary.uploader import cloudinary.api # Load environment variables from .env file (for local development) load_dotenv() # Configure Cloudinary using the CLOUDINARY_URL environment variable # Example: CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name> # Ensure this variable is set in your environment or .env file. cloudinary.config(secure=True) # Forces HTTPS URLs # Check if configuration is successful (optional, for debugging) if not cloudinary.config().cloud_name: print("Cloudinary configuration missing. Please set CLOUDINARY_URL.") exit(1) print("Cloudinary configured. Cloud name:", cloudinary.config().cloud_name) # --- Example: Upload an image --- # Replace 'my_local_image.jpg' with a path to a local image or a remote URL. # For a real application, handle file paths dynamically. try: upload_result = cloudinary.uploader.upload( "https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg", public_id="quickstart_butterfly_example", unique_filename=False, overwrite=True ) print("\nUpload successful:") print("Public ID:", upload_result['public_id']) print("Secure URL:", upload_result['secure_url']) # --- Example: Generate a transformed URL --- transformed_url = cloudinary.utils.cloudinary_url( upload_result['public_id'], width=100, height=150, crop="fill" )[0] print("Transformed URL (fill 100x150):", transformed_url) # --- Example: Get asset details (Admin API) --- asset_details = cloudinary.api.resource(upload_result['public_id']) print("\nAsset details:") print(f"Format: {asset_details['format']}, Bytes: {asset_details['bytes']}") except Exception as e: print(f"An error occurred: {e}")
Debug
Known footguns
breakingPython 2.x reached End of Life in January 2020. While older SDK versions might have supported Python 2.7, current and actively maintained versions of the Cloudinary Python SDK are developed for Python 3.x. Using Python 2.x may lead to compatibility issues and security vulnerabilities.
gotchaCloudinary API Key and Secret are sensitive credentials. Exposing them in source code or version control (e.g., directly in `settings.py` or `.env` files committed to Git) is a significant security risk.
gotchaWhen configuring Cloudinary globally (e.g., with `cloudinary.config()`) and using advanced settings like a proxy, the `cloudinary.config()` call must occur *before* importing `cloudinary.uploader` and `cloudinary.api` to ensure the settings are applied correctly for those modules.
gotchaDirect browser uploads (from client-side code) should primarily use 'unsigned upload presets'. Unsigned requests have a restricted set of parameters for security reasons. Other desired transformations or settings should be defined within the upload preset itself, rather than directly in the unsigned upload call.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources