Skip to main content

validar-iti

API e cliente Python não oficial para validar assinaturas de PDFs pelo ITI VALIDAR.

O projeto não implementa um verificador criptográfico próprio. Ele envia PDFs ou URLs para os endpoints públicos usados pelo site do VALIDAR e normaliza a resposta em JSON simples para uso em sistemas.

Aviso

Este projeto não é oficial, não é mantido pelo ITI e não tem relação com o Gov.br. O serviço VALIDAR não publica esses endpoints como API pública estável, então o contrato pode mudar.

Instalação

pip install validar-iti

Para desenvolvimento local:

python -m pip install -e ".[dev]"

Subir a API

validar-iti serve --host 127.0.0.1 --port 8000

Em desenvolvimento:

validar-iti serve --reload

Endpoints

Validar um PDF

curl -F "file=@documento_assinado.pdf;type=application/pdf" \
  http://127.0.0.1:8000/validate/file

Validar múltiplos PDFs

curl \
  -F "files=@um.pdf;type=application/pdf" \
  -F "files=@dois.pdf;type=application/pdf" \
  http://127.0.0.1:8000/validate/files

Validar URL

curl -X POST http://127.0.0.1:8000/validate/url \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/documento.pdf"}'

Healthcheck

curl http://127.0.0.1:8000/health

Uso como cliente Python

import asyncio
from validar_iti import ValidarClient


async def main():
    async with ValidarClient() as client:
        resultado = await client.validate_pdf("documento_assinado.pdf")
        print(resultado.valid)
        print(resultado.status_label)
        print(resultado.simple_report_text)


asyncio.run(main())

Resposta

A API retorna campos estruturados e também simple_report_text, montado a partir do relatório simples retornado pelo próprio VALIDAR.

Exemplo resumido:

{
  "valid": true,
  "status": "approved",
  "status_label": "Aprovado",
  "report_source": "validar_simples",
  "file_name": "documento_assinado.pdf",
  "sha256": "...",
  "signatures": [
    {
      "signer_name": "NOME DO ASSINANTE",
      "authority": "Gov-Br",
      "cpf": "***.000.000-**",
      "status": "approved",
      "status_label": "Aprovado"
    }
  ]
}

Configuração

Variáveis de ambiente:

  • VALIDAR_BASE_URL, padrão https://validar.iti.gov.br
  • VALIDAR_TIMEOUT_SECONDS, padrão 190
  • VALIDAR_MAX_CONCURRENCY, padrão 2
  • MAX_UPLOAD_MB, padrão 10
  • MAX_BATCH_MB, padrão 30
  • MAX_FILES_PER_REQUEST, padrão 10
  • VALIDAR_PROXY_URL, proxy HTTP(S) opcional para chamadas ao VALIDAR
  • VALIDAR_USE_SIMPLE_REPORT, padrão true
  • USER_AGENT, user-agent enviado ao VALIDAR

Quando VALIDAR_USE_SIMPLE_REPORT=true, o fluxo usa /arquivo ou /url e em seguida /simples, que é a fonte dos dados da visão "Simples" do relatorio.html.

Quando VALIDAR_USE_SIMPLE_REPORT=false, a biblioteca pula /simples e mapeia localmente a resposta bruta para reduzir tráfego.

Testes

python -m pytest

Teste real opcional contra o VALIDAR:

RUN_LIVE_VALIDAR_TESTS=1 python -m pytest tests/test_live_validar.py

Licença

MIT

Release files for validar-iti 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for validar-iti 1.0.0
File Size Uploaded
validar_iti-1.0.0.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for validar-iti 1.0.0
File Interpreter ABI Platform
validar_iti-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.8 kB

Release files / validar_iti-1.0.0.tar.gz

Download URL validar_iti-1.0.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5a26a84ce12f4845f69993efb30f6086fb1d87377eaf74905e31554f20711500
BLAKE2b-256 checksum
How to use checksums
81c5bf40960e7e31d315da4c8fbf4d97f5bc8c8b00688aacc22c828ce98d2c6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / validar_iti-1.0.0-py3-none-any.whl

Download URL validar_iti-1.0.0-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6afbb37e4cf4d436b2caa299191e6f7b020847938ba5883e2c555092df04ba62
BLAKE2b-256 checksum
How to use checksums
e850568225c0d6872470f9519f9ba8c4c3cea02829eb75b35e5580222c001467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page