> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Python quick start


[readme-version-support-link]:https://github.com/cloudinary/pycloudinary#Version-Support
This quick start lets you get an end-to-end implementation up and running using the Python SDK in 5 minutes or less.

#### Prerequisites **To perform this quick start, you'll need:**

* A Cloudinary account. If you don't have one yet, you can quickly [register for free](https://cloudinary.com/users/register_free).
* Your product environment credentials. You can find your [credentials](product_environment_settings#api_keys) on the [API Keys](https://console.cloudinary.com/app/settings/api-keys) page of the Cloudinary Console Settings. 
  * To use your **API environment variable**, copy the provided format and replace the `<your_api_key>` and `<your_api_secret>` placeholders with the actual values found on the page. Your cloud name will already be correctly included in the format.
* A working Python development environment with a [supported version][readme-version-support-link] of Python.

> **NOTES**:
>
> * This quick start is designed for quick onboarding.  It doesn't necessarily employ coding best practices and the code you create here isn't intended for production.  

> * If you aren't familiar with Cloudinary, you may want to first take a look at the [Developer Kickstart](dev_kickstart) for a hands-on, step-by-step introduction to Cloudinary features. You may also find our [Glossary](cloudinary_glossary) helpful to understand Cloudinary-specific terminology.
## 1. Set up and configure the SDK

In a terminal in your Python3 environment, run the following code:

```python
pip3 install cloudinary
pip3 install python-dotenv
```

In your project, create a file called `.env` containing your **API environment variable** from your product environment credentials:

.env

  

```python
# Copy and paste your API environment variable
# =============================================

CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>
```

> **INFO**:
>
> * When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret. * Don't store your `.env` under version control for maximum security.

In your project, create a new file called `my_file.py`. Copy and paste the following into this file:

my_file.py

```python

# Set your Cloudinary credentials
# ==============================
from dotenv import load_dotenv
load_dotenv()

# Import the Cloudinary libraries
# ==============================
import cloudinary
from cloudinary import CloudinaryImage
import cloudinary.uploader
import cloudinary.api

# Import to format the JSON responses
# ==============================
import json

# Set configuration parameter: return "https" URLs by setting secure=True  
# ==============================
config = cloudinary.config(secure=True)

# Log the configuration
# ==============================
print("****1. Set up and configure the SDK:****\nCredentials: ", config.cloud_name, config.api_key, "\n")

```

Tips...

* You can set any [configuration parameters](cloudinary_sdks#configuration_parameters) in this way. In this case, you're setting the `secure` parameter to ensure that `https` URLs are generated by the SDK.
* Take a look at our [Python sample projects](python_sample_projects) to help get you started.
* If you're using Django, simplify your workflow Django form and model integration classes. For more information, see [Django forms and models workflow](django_image_and_video_upload#django_forms_and_models_workflow).

## 2. Upload an image

Copy and paste this into `my_file.py`:

my_file.py (continued)

```python
def uploadImage():
  
  # Upload the image and get its URL
  # ==============================

  # Upload the image.
  # Set the asset's public ID and allow overwriting the asset with new versions
  cloudinary.uploader.upload("https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg", public_id="quickstart_butterfly", unique_filename = False, overwrite=True)

  # Build the URL for the image and save it in the variable 'srcURL'
  srcURL = CloudinaryImage("quickstart_butterfly").build_url()

  # Log the image URL to the console. 
  # Copy this URL in a browser tab to generate the image on the fly.
  print("****2. Upload an image****\nDelivery URL: ", srcURL, "\n")
```

More info about upload...

* You can upload from various sources, including local files, but for this quick start we're using a remote file available at: 
[https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg](https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg).
* We've set the [public ID](cloudinary_glossary#public_id) in this example to `quickstart_butterfly`, `filename_override` to `True`, and `unique_filename` to `False` so that if you run this quick start more than once, you'll only have one file uploaded that overwrites the previous one. Without these parameters set, the default option of using a random public ID would be applied, and a new asset would be created each time.
* See the `upload` method of the [Upload API](image_upload_api_reference#upload).
* Learn more about [uploading assets](upload_images).

## 3. Get and use details of the image 

Copy and paste this into `my_file.py`:
 

my_file.py (continued)

```python
def getAssetInfo():

  # Get and use details of the image
  # ==============================

  # Get image details and save it in the variable 'image_info'.
  image_info=cloudinary.api.resource("quickstart_butterfly")
  print("****3. Get and use details of the image****\nUpload response:\n", json.dumps(image_info,indent=2), "\n")

  # Assign tags to the uploaded image based on its width. Save the response to the update in the variable 'update_resp'.
  if image_info["width"]>900:
    update_resp=cloudinary.api.update("quickstart_butterfly", tags = "large")
  elif image_info["width"]>500:
    update_resp=cloudinary.api.update("quickstart_butterfly", tags = "medium")
  else:
    update_resp=cloudinary.api.update("quickstart_butterfly", tags = "small")
  
  # Log the new tag to the console.
  print("New tag: ", update_resp["tags"], "\n")

```

More info about getting details of an asset...

* This code snippet retrieves information about the uploaded image and tags the image accordingly.
* Use the `resource` method of the [Admin API](admin_api#resources) to get the details of your image and tag it.

## 4. Transform the image

Copy and paste this into `my_file.py`:

my_file.py (continued)

```python 
def createTransformation():

  # Transform the image
  # ==============================
  
  transformedURL = CloudinaryImage("quickstart_butterfly").build_url(width = 100, height = 150, crop = "fill")

  # Log the URL to the console
  print("****4. Transform the image****\nTransfrmation URL: ", transformedURL, "\n")

  # Use this code instead if you want to create a complete HTML image element:
  # imageTag = cloudinary.CloudinaryImage("quickstart_butterfly").image(radius="max", effect="sepia")
  # print("****4. Transform the image****\nTransfrmation URL: ", imageTag, "\n")
```

More info about transformations...

* [Transformations](transformation_reference) create a modified copy of your original image. In this case, `radius="max"` creates a copy with rounded edges and `effect="sepia"` applies a special effect. 
* Optimize your image quality and format by adding [q_auto](transformation_reference#q_auto) and [f_auto](transformation_reference#f_auto) to your transformations. 
* To return only the URL, and not the whole tag, replace `build_url` with `image`.
* When using `CloudinaryImage` instead of `cloudinary.CloudinaryImage`, make sure you use the `from cloudinary import CloudinaryImage` import statement.

## 5. Run your code

Copy and paste this into `my_file.py`:

my_file.py (continued)

```python 
def main():
  uploadImage()
  getAssetInfo()
  createTransformation()
main();
```

In the terminal, run the following command: 

```
python3 my_file.py
``` 

The following original image is uploaded to Cloudinary, tagged appropriately and accessible via the URL shown below. 

The transformed version of the image is accessible via the URL shown below.  

Original imagehttp://res.cloudinary.com/&ltcloud-name&gt/image/upload/v1/quickstart_butterfly

Transformed imagehttp://res.cloudinary.com/&ltcloud-name&gt/image/upload/e_sepiar_max/v1/quickstart_butterfly

Check your code...

When you run your file, you'll see the following as they occur:

**1. Set up and configure the SDK**: Your cloud name and API key is displayed.

**2. Upload an image**: The delivery URL of the uploaded asset is displayed. Copy the URL in a browser tab to see the generated image.

**3. Get and use details of the image**: The full JSON response of the `resources` method, listing attributes of the asset you uploaded, is displayed. It should look something like this: 
  
```
****3. Get and use details of the image****
Upload response:
 {
  "asset_id": "5df5df5df5df5df5df5df5df5df5df5d",
  "public_id": "quickstart_butterfly",
  "format": "jpg",
  "version": 1616161616,
   ...
   ...
  "secure_url": "https://res.cloudinary.com/yelenik/image/upload/v1646750443/quickstart_butterfly.jpg",
  "tags": [
  ],
  "metadata": {}
} 
```

The tag that was added using the `update` method is also displayed: 

```
New tag:  ['large'] 
```
**4. Transform the image**: The HTML image tag for your transformed image is displayed. You can use this on an HTML page, and your transformed image will be generated on the fly.

## View the completed code

You can find the full code example for this quick start on [GitHub](https://github.com/cloudinary-devs/python-sdk-quickstart).

## Next steps
* Learn more about the Python SDK by visiting the other pages in this SDK guide.
* Get comprehensive details about Cloudinary features and capabilities:
    * [Upload guide](upload_images): Provides details and examples of the upload options.
    * [Image transformations guide](image_transformations): Provides details and examples of the transformations you can apply to image assets.
    * [Video transformations guide](video_manipulation_and_delivery): Provides details and examples of the transformations you can apply to video assets.
    * [Transformation URL API Reference](transformation_reference): Provides details and examples of all available transformation parameters. 
    * [Admin API guide](admin_api): Provides details and examples of the methods available for managing and organizing your media assets.