Skip to main content

Biblioteca Python com ferramentas para execução de consultas SQL via API REST do Protheus (TOTVS)

Project description

ProtheusTools

Biblioteca Python com ferramentas para execução de consultas SQL via API REST do Protheus (TOTVS). Os resultados são retornados como pandas.DataFrame.

Instalação

pip install protheustools

Uso

Consultar dados do Protheus

from protheustools import exec_query

df = exec_query(
    query="SELECT A1_COD, A1_NOME FROM SA1010 WHERE D_E_L_E_T_ = ''",
    username="seu_usuario",
    password="sua_senha",
    url="https://seu-servidor.protheus.cloudtotvs.com.br:4050/rest_prd",
)

print(df.head())

Parâmetros de exec_query

Parâmetro Tipo Padrão Descrição
query str Query SQL a ser executada no Protheus
username str Usuário de autenticação da API REST
password str Senha de autenticação da API REST
url str URL base da API REST do Protheus
useDictionary bool False Usa o dicionário de dados do Protheus

Retorno

Retorna um pandas.DataFrame com os resultados da query.

Em caso de erro, levanta exceções:

Exceção Quando ocorre
ValueError query, url ou credenciais não informados
ValueError Erro ao codificar o payload da requisição
ValueError Redirecionamento inesperado (HTTP 3xx)
ValueError Erro do cliente na API (HTTP 4xx) — inclui a mensagem de erro da API
ValueError Erro do servidor (HTTP 5xx) — inclui a mensagem de erro
ValueError Erro ao decodificar a resposta da API
ConnectionError Falha na conexão com a API do Protheus

Gerenciar informações de localização e timezone

Obter informações de localização

from protheustools import get_locale_info

info = get_locale_info()
print(info)
# {
#     'country': 'BR',
#     'region': 'SP',
#     'city': 'São Paulo',
#     'ip': '192.168.1.1',
#     'hostname': 'meu-pc',
#     'timezone': 'America/Sao_Paulo',
#     'firewall_tcloud': True
# }

Nota: Esta função verifica automaticamente se seu IP está em um país permitido pelo firewall do TCloud (Brasil, Estados Unidos ou Canadá).

Obter timezone atual

from protheustools import get_timezone

tz = get_timezone()
print(tz)  # 'America/Sao_Paulo'

Definir timezone

from protheustools import set_timezone

set_timezone('America/Sao_Paulo')  # Padrão
# ou
set_timezone('America/New_York')

Detectar Google Colab

from protheustools import is_colab

if is_colab():
    print("Executando no Google Colab")
else:
    print("Executando localmente")

Requisitos

  • Python 3.8+
  • requests >= 2.28.0
  • pandas >= 1.5.0
  • tzlocal >= 4.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

protheustools-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

protheustools-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file protheustools-0.1.0.tar.gz.

File metadata

  • Download URL: protheustools-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for protheustools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1733e281aff00d87a63d992a0ff59104091323e5871c4928a069ae1e0c203b5e
MD5 ae195fe16ca6ccfacc96c215d13fe701
BLAKE2b-256 187ab79d89a0981e72b5700fe5ebd1ff02349ae84e14e4d66713fa719771970e

See more details on using hashes here.

File details

Details for the file protheustools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: protheustools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for protheustools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5afd0ae071129c1f31b08e747418c4676ac76269de83a57187c1bd5f2733dad1
MD5 0a9bf87191602852a077316004fb1245
BLAKE2b-256 c931f7fd669946a3376c7d504afd33b7f36dd380080d9c8765ed2bbdce4be08c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page