Programmable Media

Python sample projects

Last updated: Aug-04-2024

We've created some sample projects to get you started with integrating Cloudinary into your Python applications, featuring both Django and Flask frameworks.

Tip
Check out our collection of Python code explorers too!

Django photo album

The Django photo album app showcases various functionalities such as uploading, saving delivery URLs to the database, transforming, and delivering images. In particular, explore how to upload images through your server or via signed and unsigned uploads directly from the browser. Additionally, learn how to apply smart-cropping to uploaded images to fit them in a square and save their delivery URLs to your database. Finally, view all uploaded images displayed in a photo album and seamlessly apply transformations on-the-fly.

This is the Django photo album app in action:


Here's an excerpt from the code featuring a CloudinaryField within the Photo table of the models.py file, intended for storing Cloudinary URLs in the database. Additionally, the CloudinaryJsFileField is utilized in the forms.py file to capture and transform images uploaded to Cloudinary via a form.

models.py

forms.py


Django form and model helpers

The django_cloudinary_app folder in the my-django-app repository demonstrates seamlessly integrating Cloudinary features while preserving your standard workflow of saving delivery URLs directly into your database during uploads. Learn how to upload images to Cloudinary, apply transformations, and store their Cloudinary delivery URLs in your database using Cloudinary's form and model helper classes.

Furthermore, within the my-django-app repository, you'll find a django_app folder containing the same application without Cloudinary integration. This application serves as a reference point for comparison. You can review the code that requires modification to integrate Cloudinary. Notice the enhancements Cloudinary brings, including optimized image sizes and improved resize and cropping functionality.

This is the Django form and model helpers app in action:


Here's an excerpt from the code for configuring a form and table to enable users to select images for uploading to Cloudinary. After uploading, the URLs for accessing these images are stored in the database.

forms.py

models.py

views.py


Basic Flask - image uploader and transformer

The Basic Flask - image uploader and transformer demonstrates how you can upload images to Cloudinary and display them on a webpage with various transformations applied.

This is the Flask image uploader and transformer app in action:


Here's an excerpt from the code that handles a user-select image passed to the backend using a form. It uploads these images to Cloudinary and then displays both the original and transformed versions on-the-fly.

app.py


Flask product recommendations

This app serves as a recommendation engine for products based on user-selected images. Users can choose product images that are auto-tagged, and the app analyzes them to identify common themes or tags. It then suggests other images with similar themes, providing recommendations for users to explore further.

This is the Flask product recommendations app in action:


Here's an excerpt from the code that defines the /output route for processing a POST request, where it captures user-selected images. It then identifies common themes based on the images' auto-tags and suggests similarly tagged images for further exploration.

demo.py


Image pre-processing and augmentation

This Jupyter notebook shows examples of pre-processing and augmenting images for machine learning by applying transformations. You can read more about it in this blog post.

This is the image pre-processing and augmentation Jupyter notebook in action:


Here's an excerpt from the code that establishes an upload preset tailored to pre-process images by smart-cropping them to a size of 400x400 pixels. This preset is automatically applied during the upload process. Furthermore, saturation is applied as an augmentation to enhance the flexibility of the image model that this image is being prepared for.

samples.ipynb

✔️ Feedback sent!

Rate this page: