DEV Community

Fabian Anguiano
Fabian Anguiano

Posted on

Automating Product Descriptions in Odoo with OpenAI's GPT-3 and Python


If you're managing an online store or any business that requires a catalog of products, you know how time-consuming it can be to write unique and engaging product descriptions. What if there was a way to automate this process?

In this tutorial, we'll walk you through how to automatically generate product descriptions in Odoo using OpenAI's GPT-3. We'll use Python to bridge the gap between Odoo and OpenAI's API. Don't worry if you're not a coding expert; we'll guide you through each step, including an explanation of the code.


  1. Odoo Account: You should have an Odoo instance where you can add or update products.
  2. OpenAI API Key: Get an API key from OpenAI by signing up at their Developer Dashboard.
  3. Python 3.x: Make sure Python is installed on your machine. You can download it from here.

For more Python and Odoo scripts, you can check out this GitHub repository: Odoo Unable to Unreserve Fix Script.

Step-by-Step Guide

Step 1: Install Required Python Packages

First, you need to install some Python packages that our script will use. Open your terminal and run:

pip install xmlrpc.client openai configparser

Step 2: Create a Configuration File

Create a new text file named config.ini\ in your working directory and paste the following:



Replace the placeholders with your actual OpenAI API key and Odoo credentials.

Step 3: Write the Python Script

Create a new Python file (\) and paste the script shared at the beginning of this article. Save the file.

Step 4: Understanding the Code

The script is divided into several key parts:

  1. SSL Configuration: This part of the code sets up a secure connection for the script. This is especially important if you're working in an environment that requires secure HTTPS connections but doesn't support HTTPS verification.

    _create_unverified_https_context = ssl._create_unverified_context
    except AttributeError:
    ssl._create_default_https_context = _create_unverified_https_context

  2. Loading Configurations: Here, we read the OpenAI and Odoo details from the config.ini\ file you created earlier.

    config = configparser.ConfigParser()'config.ini')

  3. Odoo Login: This part logs you into your Odoo account and sets up the XML-RPC clients needed to interact with Odoo's API.

    common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
    uid = common.authenticate(db, username, password, {})
    models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

  4. Fetching Products: This part fetches the first 100 products from your Odoo database.

    product_ids = models.execute_kw(db, uid, password,
    'product.template', 'search',
    {'limit': 100})

  5. Updating Descriptions: Here, for each product, we call the OpenAI API to generate a product description and then update the product in Odoo.

    for product in products:
    response = openai.Completion.create(
    prompt=f"Describe the product: {product['name']}",
    description = response.choices[0].text.strip()

Step 5: Run the Script

Open your terminal, navigate to the folder where\ is saved, and run:


Step 6: Verify the Changes

Log in to your Odoo account and navigate to the products. You should see that the product descriptions have been updated.


Automating product descriptions can save you a lot of time and effort. With just a few lines of Python code, we've created a powerful tool that uses OpenAI's GPT-3 to generate product descriptions and updates them in Odoo. This tutorial not only guides you through how to set up and use the script but also provides an in-depth explanation of how the code works. Happy automating!

Top comments (0)