How josespx/apiconsultasunatruc works
Consulta RUC Sunat is a Flask API that retrieves taxpayer details from SUNAT in real time. The main workflow validates a submitted RUC, obtains SUNAT’s CAPTCHA image and cookies, OCRs the image, uses the recognized text to request taxpayer data, parses the returned HTML, and serializes the result as JSON. The API also exposes a simple health response. The graph follows the sampled route and helper calls; the README documents scraping and OCR, while wiring beyond those excerpts is omitted.
Main entry points: sunat.py RUC Endpoint · tesseract.py Image OCR · sunatinfo.py Field Parser · __init__.py Flask App
Components 12
API
- Flask App
app/__init__.py - RUC Endpoint
app/routes/sunat.py - Health Endpoint
app/routes/home.py
CAPTCHA OCR
- Image OCR
app/helpers/tesseract.py - Tesseract OCR
SUNAT Lookup
- HTML Retrieval
app/helpers/sunatinfo.py - Field Parser
app/helpers/sunatinfo.py - Layout Constants
app/helpers/sunatconstants.py - Taxpayer Model
app/models/sunatinfo.py
Runtime Configuration
- SUNAT Settings
config.py
Other components
- API Client
- SUNAT Service
Connections 16
- API Client → RUC Endpoint: submits RUC
- RUC Endpoint → API Client: returns JSON
- API Client → Health Endpoint: checks status
- Health Endpoint → API Client: returns status
- Flask App → RUC Endpoint: registers route
- Flask App → Health Endpoint: registers route
- SUNAT Settings → Flask App: configures
- RUC Endpoint → Image OCR: requests CAPTCHA text
- Image OCR → SUNAT Service: fetches CAPTCHA
- Image OCR → Tesseract OCR: recognizes text
- RUC Endpoint → HTML Retrieval: requests taxpayer data
- HTML Retrieval → SUNAT Service: fetches HTML
- RUC Endpoint → Field Parser: parses rows
- Field Parser → Layout Constants: reads field indices
- Field Parser → Taxpayer Model: populates model
- RUC Endpoint → Taxpayer Model: serializes response