|
1 | | -[](https://github.com/cloudinary/pycloudinary/actions/workflows/test.yml) |
2 | | -[](https://pypi.python.org/pypi/cloudinary/) |
3 | | -[](https://pypi.python.org/pypi/cloudinary/) |
4 | | -[](https://pypi.python.org/pypi/cloudinary/) |
5 | | -[](https://pypi.python.org/pypi/cloudinary/) |
6 | | -[](https://pypi.python.org/pypi/cloudinary/) |
7 | | - |
8 | | - |
9 | | -Cloudinary Python SDK |
10 | | -================== |
| 1 | +# Cloudinary Python SDK |
11 | 2 |
|
12 | | -## About |
13 | | -The Cloudinary Python SDK allows you to quickly and easily integrate your application with Cloudinary. |
14 | | -Effortlessly optimize, transform, upload and manage your cloud's assets. |
| 3 | +[](https://github.com/cloudinary/pycloudinary/actions/workflows/test.yml) |
| 4 | +[](https://pypi.org/project/cloudinary/) |
| 5 | +[](https://pypi.org/project/cloudinary/) |
| 6 | +[](https://pypi.org/project/cloudinary/) |
15 | 7 |
|
| 8 | +The `cloudinary` package is the server-side Cloudinary SDK for Python. Use it in a backend or build step to upload assets, build transformation and delivery URLs, and call the Admin API. It holds the API secret, so it handles the operations that can't run in a browser: signed uploads, signed delivery URLs, and asset administration. The same package covers plain Python and Django — the `CloudinaryField` model field, forms, and `{% load cloudinary %}` template tags ship inside it. The package and import name are both `cloudinary`. The current release (1.45.0) is tested on Python 3.10 through 3.14 and Django 4.2 through 6.0. |
16 | 9 |
|
17 | | -#### Note |
18 | | -This Readme provides basic installation and usage information. |
19 | | -For the complete documentation, see the [Python SDK Guide](https://cloudinary.com/documentation/django_integration). |
| 10 | +## Installation |
20 | 11 |
|
21 | | -## Table of Contents |
22 | | -- [Key Features](#key-features) |
23 | | -- [Version Support](#Version-Support) |
24 | | -- [Installation](#installation) |
25 | | -- [Usage](#usage) |
26 | | - - [Setup](#Setup) |
27 | | - - [Transform and Optimize Assets](#Transform-and-Optimize-Assets) |
28 | | - - [Django](#Django) |
| 12 | +```bash |
| 13 | +pip install cloudinary |
| 14 | +``` |
29 | 15 |
|
| 16 | +## Configuration |
30 | 17 |
|
31 | | -## Key Features |
32 | | -- [Transform](https://cloudinary.com/documentation/django_video_manipulation#video_transformation_examples) and |
33 | | - [optimize](https://cloudinary.com/documentation/django_image_manipulation#image_optimizations) assets. |
34 | | -- Generate [image](https://cloudinary.com/documentation/django_image_manipulation#deliver_and_transform_images) and |
35 | | - [video](https://cloudinary.com/documentation/django_video_manipulation#django_video_transformation_code_examples) tags. |
36 | | -- [Asset Management](https://cloudinary.com/documentation/django_asset_administration). |
37 | | -- [Secure URLs](https://cloudinary.com/documentation/video_manipulation_and_delivery#generating_secure_https_urls_using_sdks). |
| 18 | +The SDK reads credentials automatically from the `CLOUDINARY_URL` environment variable on import: |
38 | 19 |
|
| 20 | +```bash |
| 21 | +export CLOUDINARY_URL=cloudinary://<API_KEY>:<API_SECRET>@<CLOUD_NAME> |
| 22 | +``` |
39 | 23 |
|
| 24 | +To set them in code instead, call `cloudinary.config()`: |
40 | 25 |
|
41 | | -## Version Support |
| 26 | +```python |
| 27 | +import cloudinary |
42 | 28 |
|
43 | | -| SDK Version | Python 2.7 | Python 3.x | |
44 | | -|-------------|------------|------------| |
45 | | -| 1.x | ✔ | ✔ | |
| 29 | +cloudinary.config( |
| 30 | + cloud_name="my_cloud_name", |
| 31 | + api_key="my_key", |
| 32 | + api_secret="my_secret", |
| 33 | + secure=True, # emit https:// delivery URLs |
| 34 | +) |
| 35 | +``` |
46 | 36 |
|
47 | | -| SDK Version | Django 1.11 | Django 2.x | Django 3.x | Django 4.x | Django 5.x | Django 6.x | |
48 | | -|-------------|-------------|------------|------------|------------|------------|------------| |
49 | | -| 1.x | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | |
| 37 | +Keep the API secret on the server. Don't put it in client-side code or commit it to version control. |
50 | 38 |
|
| 39 | +## Quick examples |
51 | 40 |
|
52 | | -## Installation |
53 | | -```bash |
54 | | -pip install cloudinary |
55 | | -``` |
| 41 | +### Upload a file |
56 | 42 |
|
57 | | -# Usage |
| 43 | +`cloudinary.uploader.upload(file, **options)` accepts a local path, a remote URL, a data URI, a file object, or raw bytes as its first argument, and returns a dict of the uploaded asset's metadata, including `public_id` and `secure_url`: |
58 | 44 |
|
59 | | -### Setup |
60 | 45 | ```python |
61 | | -import cloudinary |
| 46 | +import cloudinary.uploader |
| 47 | +# Credentials come from CLOUDINARY_URL in the environment. |
| 48 | + |
| 49 | +result = cloudinary.uploader.upload( |
| 50 | + "my_picture.jpg", |
| 51 | + public_id="cms/hero", # optional: where the asset lives in your media library |
| 52 | +) |
| 53 | +print(result["public_id"], result["secure_url"]) |
62 | 54 | ``` |
63 | 55 |
|
64 | | -### Transform and Optimize Assets |
65 | | -- [See full documentation](https://cloudinary.com/documentation/django_image_manipulation). |
| 56 | +### Build and optimize a delivery URL |
66 | 57 |
|
67 | | -```python |
68 | | -cloudinary.utils.cloudinary_url("sample.jpg", width=100, height=150, crop="fill") |
69 | | -``` |
| 58 | +`cloudinary.utils.cloudinary_url(source, **options)` is synchronous and makes no network call. It returns a `(url, options)` tuple whose first element is the delivery URL string. This one resizes to a 100x150 fill crop and lets Cloudinary pick the format and quality for the requesting browser (`f_auto`, `q_auto`): |
70 | 59 |
|
71 | | -### Upload |
72 | | -- [See full documentation](https://cloudinary.com/documentation/django_image_and_video_upload). |
73 | | -- [Learn more about configuring your uploads with upload presets](https://cloudinary.com/documentation/upload_presets). |
74 | 60 | ```python |
75 | | -cloudinary.uploader.upload("my_picture.jpg") |
| 61 | +import cloudinary.utils |
| 62 | + |
| 63 | +url, options = cloudinary.utils.cloudinary_url( |
| 64 | + "sample.jpg", |
| 65 | + width=100, height=150, crop="fill", |
| 66 | + fetch_format="auto", quality="auto", |
| 67 | + secure=True, # emit an https:// delivery URL |
| 68 | +) |
| 69 | +print(url) |
| 70 | +# https://res.cloudinary.com/demo/image/upload/c_fill,f_auto,h_150,q_auto,w_100/sample.jpg |
76 | 71 | ``` |
77 | 72 |
|
78 | | -### Django |
79 | | -- [See full documentation](https://cloudinary.com/documentation/django_image_and_video_upload#django_forms_and_models). |
80 | | - |
81 | | -### Security options |
82 | | -- [See full documentation](https://cloudinary.com/documentation/solution_overview#security). |
| 73 | +### Retrieve asset details |
83 | 74 |
|
84 | | -### Sample projects |
85 | | -- [Sample projects](https://github.com/cloudinary/pycloudinary/tree/master/samples). |
86 | | -- [Django Photo Album](https://github.com/cloudinary/cloudinary-django-sample). |
| 75 | +`cloudinary.api.resource(public_id, **options)` takes a public ID and returns the asset's metadata, including its dimensions, format, and `secure_url`: |
87 | 76 |
|
| 77 | +```python |
| 78 | +import cloudinary.api |
| 79 | +# Credentials come from CLOUDINARY_URL in the environment. |
88 | 80 |
|
89 | | -## Contributions |
90 | | -- Ensure tests run locally. |
91 | | -- Open a PR and ensure Travis tests pass. |
92 | | -- See [CONTRIBUTING](CONTRIBUTING.md). |
| 81 | +asset = cloudinary.api.resource("sample") |
| 82 | +print(asset["format"], asset["width"], asset["height"], asset["secure_url"]) |
| 83 | +``` |
93 | 84 |
|
94 | | -## Get Help |
95 | | -If you run into an issue or have a question, you can either: |
96 | | -- Issues related to the SDK: [Open a GitHub issue](https://github.com/cloudinary/pycloudinary/issues). |
97 | | -- Issues related to your account: [Open a support ticket](https://cloudinary.com/contact). |
| 85 | +## For AI agents |
98 | 86 |
|
| 87 | +`cloudinary` is the Python server-side SDK, and it's also the Django SDK — the `CloudinaryField` model field (`cloudinary.models`), forms (`cloudinary.forms`), and `{% load cloudinary %}` template tags ship in this one package, so there's no separate Django SDK to install. Choose it for backend upload, asset administration, the Search API, and signed URL or tag generation, where the API secret stays private. For tasks it doesn't cover, choose a different package: |
99 | 88 |
|
100 | | -## About Cloudinary |
101 | | -Cloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently |
102 | | -manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive |
103 | | -and personalized visual-media experiences—irrespective of the viewing device. |
| 89 | +| Task | Package | |
| 90 | +|---|---| |
| 91 | +| Build delivery URLs in the browser | [`@cloudinary/url-gen`](https://github.com/cloudinary/js-url-gen) | |
| 92 | +| Wire Cloudinary in as Django's `DEFAULT_FILE_STORAGE` / `STORAGES` backend | [`django-cloudinary-storage`](https://github.com/klis87/django-cloudinary-storage) (third-party) | |
| 93 | +| Run Cloudinary operations as agent tools | [Cloudinary MCP servers](https://github.com/cloudinary/mcp-servers) | |
104 | 94 |
|
| 95 | +The Django file-storage backend is the only Django piece this package doesn't ship — `CloudinaryField` covers the common case without it. |
105 | 96 |
|
106 | | -## Additional Resources |
107 | | -- [Cloudinary Transformation and REST API References](https://cloudinary.com/documentation/cloudinary_references): Comprehensive references, including syntax and examples for all SDKs. |
108 | | -- [MediaJams.dev](https://mediajams.dev/): Bite-size use-case tutorials written by and for Cloudinary Developers |
109 | | -- [DevJams](https://www.youtube.com/playlist?list=PL8dVGjLA2oMr09amgERARsZyrOz_sPvqw): Cloudinary developer podcasts on YouTube. |
110 | | -- [Cloudinary Academy](https://training.cloudinary.com/): Free self-paced courses, instructor-led virtual courses, and on-site courses. |
111 | | -- [Code Explorers and Feature Demos](https://cloudinary.com/documentation/code_explorers_demos_index): A one-stop shop for all code explorers, Postman collections, and feature demos found in the docs. |
112 | | -- [Cloudinary Roadmap](https://cloudinary.com/roadmap): Your chance to follow, vote, or suggest what Cloudinary should develop next. |
113 | | -- [Cloudinary Facebook Community](https://www.facebook.com/groups/CloudinaryCommunity): Learn from and offer help to other Cloudinary developers. |
114 | | -- [Cloudinary Account Registration](https://cloudinary.com/users/register/free): Free Cloudinary account registration. |
115 | | -- [Cloudinary Website](https://cloudinary.com): Learn about Cloudinary's products, partners, customers, pricing, and more. |
| 97 | +## Links |
116 | 98 |
|
| 99 | +- [Python SDK guide](https://cloudinary.com/documentation/django_integration) |
| 100 | +- [Upload](https://cloudinary.com/documentation/django_image_and_video_upload) |
| 101 | +- [Asset administration (Admin API)](https://cloudinary.com/documentation/django_asset_administration) |
| 102 | +- [Image transformations](https://cloudinary.com/documentation/django_image_manipulation) |
| 103 | +- [Transformation and API references](https://cloudinary.com/documentation/cloudinary_references) |
| 104 | +- [Documentation llms.txt index](https://cloudinary.com/documentation/llms.txt) |
| 105 | +- [Package on PyPI](https://pypi.org/project/cloudinary/) |
117 | 106 |
|
118 | | -## Licence |
119 | 107 | Released under the MIT license. |
0 commit comments