---
title: "PEP8 Conversion"
canonical: https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance/tools/pep8-conversion
markdown: https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance/tools/pep8-conversion.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/01%20Cloud%20Platform/99%20API%20Reference/10%20AI%20Assistance/02%20Tools/04%20PEP8%20Conversion
modified: 2026-10-28
index: https://www.quantconnect.com/llms.txt
---

# PEP8 Conversion

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Cloud Platform](https://www.quantconnect.com/docs/v2/cloud-platform.md) > [API Reference](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference.md) > [AI Assistance](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance.md) > [Tools](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance/tools.md) > PEP8 Conversion

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

Update Python code to follow PEP8 style.

## Request

Update Python code to follow PEP8 style. The `/ai/tools/pep8-convert` API accepts requests in the following format:

| `PEP8ConvertRequest` Model - Request to convert Python code to PEP8 style. |  |
| --- | --- |
| files | `File Array required example: [{"name": "file.py", "content": "fileContent"}]` Files of the project. |
| Example | `{ "files": "[{"name": "file.py", "content": "fileContent"}]" ] }` |

| `File` Model - File for a AI. |  |
| --- | --- |
| name | `string example: main.py` Name of a file. |
| content | `string` Contents of the file. |
| Example | `{ "name": "main.py", "content": "string" }` |

## Responses

The `/ai/tools/pep8-convert` API provides a response in the following format:

### 200 Success

| `PEP8ConvertResponse` Model - Response to a PEP8 conversion request. |  |
| --- | --- |
| state | `string example: End` State of PEP8 conversion. |
| version | `number example: 2.0` Version of the response. |
| payload | `object example: {'utils.py': 'def add(a,b):\n return a+b\n'}` A dictionary where the key is the file name and the value is the PEP8 converted code of that file. |
| payloadType | `string example: StringDict` Type of the payload. |
| Example | `{ "state": "End", "version": 2.0, "payload": { "utils.py": "def add(a,b):\n return a+b\n" }, "payloadType": "StringDict" }` |

### 401 Authentication Error

| `UnauthorizedError` Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash. |  |
| --- | --- |
| www_authenticate | `string` Header |

## Examples

The following example demonstates PEP8 conversion of python codes through the cloud API.

```
from base64 import b64encode
from hashlib import sha256
from time import time
from requests import get, post
BASE_URL = 'https://www.quantconnect.com/api/v2/'

# You need to replace these with your actual credentials.
# You can request your credentials at https://www.quantconnect.com/settings/
# You can find our organization ID at https://www.quantconnect.com/organization/
USER_ID = 0
API_TOKEN = '____'
ORGANIZATION_ID = '____'

def get_headers():
    # Get timestamp
    timestamp = f'{int(time())}'
    time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8')

    # Get hased API token
    hashed_token = sha256(time_stamped_token).hexdigest()
    authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8')
    authentication = b64encode(authentication).decode('ascii')

    # Create headers dictionary.
    return {
        'Authorization': f'Basic {authentication}',
        'Timestamp': timestamp
    }

# Authenticate to verify credentials
response = post(f'{BASE_URL}/authenticate', headers = get_headers())
print(response.json())

# --------------------

### PEP8 Conversion
# Send a POST request to the /ai/tools/pep8-convert endpoint to convert code to PEP8 syntax
response = post(f'{BASE_URL}/ai/tools/pep8-convert', headers=get_headers(), json={
    "files": [  # List of files to convert
        {
            "name": "utils.py",  # Name of the file
            "content": '''
# region imports
from AlgorithmImports import *
# endregion

class Project(QCAlgorithm):

    def Initialize(self):
        self.AddEquity("SPY", Resolution.Minute)
'''  # Content of the file (Python code)
        }
    ]
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the PEP8 conversion results
if result['success']:
    print("PEP8 Conversion Results:")
    print(result)
```
