# Programação em Python

## Como executar código-fonte Python no Mavibot.ai

Para executar um código-fonte (extensão .py), a função **code\_executor(URL, params)** é usada, onde

**URL** - a URL para o código-fonte (“<https://mavibot.ai/handler.py”> como exemplo)

**params** - os parâmetros necessários para o seu código (eles vêm como uma linha JSON)

O valor retornado é o que a função retorna

Exemplo:

![](https://lh5.googleusercontent.com/LS-DvyjzFkpV6FMf1xDu_lgBMle_VulqC6M2W1SIQdu_q7GzALODAfVzU4Xu41O-hk7_hRJvAxHL-GHzqWT5Gmn5WYntvr-KdmgxhBPqxxQ14l5Vs7cuPIkLEnisPcrFoCkLKiKfEky3VgOsDg)

{% hint style="success" %}
Se você precisar enviar solicitações de API de um endereço IP russo, recomendamos usar o proxy do Salebot.

Exemplo:

requests.get('<https://google.com>', proxies={'https': '[http://51.250.88.121:24532'}).text](https://docs.mavibot.ai/doc/pt/recursos-especiais/http:/51.250.88.121:24532'}\).text)
{% endhint %}

{% hint style="info" %}
`139.59.148.123` — executor de código Python
{% endhint %}

**Requisitos para o código-fonte:**

Seu código deve incluir uma função handle(data) que aceite um parâmetro contendo um hash dos parâmetros que você especificou nas configurações do bloco. A função deve retornar um valor que será repassado ao bot após a execução. Para dividir o resultado nos parâmetros do editor, retorne-o como JSON.

Um exemplo de código você pode ver aqui: <https://mavibot.ai/handler.py>

Você pode usar bibliotecas padrão, bem como as listadas abaixo:

requests \
logger \
gspread \
oauth2client \
numpy \
pyzbar \
fuzzywuzzy \
python-Levenshtein \
re \
urllib \
time \
json \
hmac \
hashlib \
beautifulsoup4 \
pandas \
base64 \
xmltodict \
mysql-connector-python \
zeep \
Google-api-python-client

### Visão geral em vídeo


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/doc/pt/recursos-especiais/programacao-em-python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
