Python API to interact with Escavador endpoints
Project description
escavador-api
A Python library for interacting with the Escavador API, providing access to Brazilian legal process data, documents, and monitoring services.
Features
- Process Information: Retrieve detailed information about legal processes using CNJ numbers
- Process Movements: Get chronological movement history of legal processes
- Document Access: Download public and restricted process documents
- AI Summaries: Generate and retrieve AI-powered process summaries
- Process Monitoring: Set up monitoring for new processes or updates to existing processes
- Credit Management: Check API usage credits and limits
- Process Updates: Request fresh data updates from court sources
- Retry Logic: Automatic retry with 5-second delays for network failures (max 5 retries)
Installation
From Source
git clone https://github.com/Murabei-OpenSource-Codes/escavador-api.git
cd escavador-api
pip install .
Requirements
- Python >= 3.12
- requests >= 2.32.5
Quick Start
from escavador_api import EscavadorAPI
# Initialize with your API token
api = EscavadorAPI("your_auth_token_here")
# Check credit balance
balance = api.get_credit_balance()
print(balance)
# Get process information
process_info = api.get_process_info("12345678901234567890")
print(process_info)
API Reference
Initialization
EscavadorAPI(escavador_auth_token: str)
Parameters:
escavador_auth_token(str): Your Escavador API authentication token
Core Methods
Credit Management
get_credit_balance() -> dict
Returns current credit balance and monthly limits.
Process Information
get_process_info(process_number: str) -> dict
Retrieve basic process information.
Parameters:
process_number(str): CNJ process number (20 digits, punctuation optional)
get_process_movements(process_number: str) -> list
Get all movements for a process.
get_process_public_documents(process_number: str) -> list
Get publicly available documents.
get_process_all_documents(process_number: str) -> list
Get all documents (public and restricted, if authorized).
Process Updates
request_process_update_public(process_number: str) -> dict
Request update of public process information.
request_process_update_full(
process_number: str,
auth_username: str = None,
auth_password: str = None,
certificate_id: int = None,
use_certificate: bool = False
) -> dict
Request full update including restricted documents.
get_process_update_status(process_number: str) -> dict
Check the status of an update request.
Document Downloads
download_process_file(process_number: str, file_key: str) -> bytes
Download a specific document as PDF bytes.
AI Summaries
request_ai_summary(process_number: str) -> dict
Request generation of an AI summary.
get_ai_summary_status(process_number: str, summary_id: int) -> dict
Check AI summary generation status.
get_ai_summary(process_number: str) -> dict
Retrieve the generated AI summary.
Monitoring
New Process Monitoring
create_monitoring_new_process(
keyword: str,
keyword_variations: list[str] = None,
aux_keywords: list[KeywordDict] = None,
courts: list[str] = None
) -> dict
Create monitoring for new processes matching criteria.
list_monitoring_new_process() -> list
List all new process monitorings.
get_monitoring_new_process(monitoring_id: int) -> dict
Get details of a specific monitoring.
edit_monitoring_new_process(
monitoring_id: int,
keyword_variations: list[str] = None,
aux_keywords: list[KeywordDict] = None,
courts: list[str] = None
) -> dict
Edit an existing monitoring.
delete_monitoring_new_process(monitoring_id: int) -> bool
Delete a monitoring.
get_results_monitoring_new_process(monitoring_id: int) -> list
Get results from a monitoring.
Existing Process Monitoring
create_monitoring_existing_process(
process_number: str,
court: str = None,
frequency: str = None
) -> dict
Monitor updates to an existing process.
list_monitoring_existing_process() -> list
List existing process monitorings.
get_monitoring_existing_process(monitoring_id: int) -> dict
Get monitoring details.
delete_monitoring_existing_process(monitoring_id: int) -> bool
Delete monitoring.
Error Handling
The library provides specific exception types:
EscavadorAPIInvalidDocumentException: Invalid process number formatEscavadorAPIProblemAPIException: API-specific errors (authentication, insufficient credits, etc.)EscavadorAPIUnmappedErrorException: Unexpected errors or network issues
Retry Logic
All API calls include automatic retry logic:
- Maximum retries: 5 attempts
- Retry delay: 5 seconds between attempts
- Retry conditions: Network errors (connection failures, timeouts, chunked encoding errors)
- Non-retryable errors: Validation errors, HTTP errors (4xx/5xx), and API-specific exceptions
Process Number Format
Process numbers must follow the Brazilian CNJ (Conselho Nacional de Justiça) format:
- 20 digits total
- Format: NNNNNNN-DD.AAAA.J.TR.OOOO
The library automatically validates process numbers and accepts them with or without punctuation.
Authentication
To use the Escavador API, you need:
- An Escavador account
- An API authentication token
- Sufficient credits for API calls
For restricted documents, additional authentication may be required (username/password or digital certificate).
Development
Setup
# Install dependencies
pip install -e .
# Run tests
pytest
# Build package
./build.sh
Testing
Tests require environment variables:
ESCAVADOR_AUTH_TOKEN: Your API tokenTEST_PROCESS_NUMBER: A valid CNJ process number for testing
export ESCAVADOR_AUTH_TOKEN="your_token"
export TEST_PROCESS_NUMBER="process_number"
pytest
License
BSD 3-Clause License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Support
For issues and questions:
- Check the Escavador API documentation
- Open an issue on GitHub
- Contact Murabei Data Science at a.baceti@murabei.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file escavador_api-0.1.8.tar.gz.
File metadata
- Download URL: escavador_api-0.1.8.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf38d1ee93f84cff6920fbe5458ec850d8b7569c1ba60117b0691f86389e9555
|
|
| MD5 |
d9ec0e5659e110971b2db4efea52c39b
|
|
| BLAKE2b-256 |
db0e68908a7842d254fe51d07dafee205833ca9866654019e58a131573468012
|
File details
Details for the file escavador_api-0.1.8-py3-none-any.whl.
File metadata
- Download URL: escavador_api-0.1.8-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c74b59b75866072a4bb3cd041e30bbb9a69db7d3ff0cc86d1bc958223267873
|
|
| MD5 |
735d233d4d180a034a4680e6cafe7786
|
|
| BLAKE2b-256 |
bcf4d7f5c686f864e741b5cded1ad7542d2c969a7ce2ca2d302d7a11176e8461
|