Last active
September 25, 2024 18:38
-
-
Save erajuan/1d43b275290ee3962a8a2f07e80f48c3 to your computer and use it in GitHub Desktop.
Consulta de api ruc sunat, api dni reniec y tipo de cambio sunat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Optional | |
import logging | |
import requests | |
class ApisNetPe: | |
BASE_URL = "https://api.apis.net.pe" | |
def __init__(self, token: str = None) -> None: | |
self.token = token | |
def _get(self, path: str, params: dict): | |
url = f"{self.BASE_URL}{path}" | |
headers = { | |
"Authorization": self.token, | |
"Referer": "https://apis.net.pe/api-tipo-cambio.html" | |
} | |
response = requests.get(url, headers=headers, params=params) | |
if response.status_code == 200: | |
return response.json() | |
elif response.status_code == 422: | |
logging.warning(f"{response.url} - invalida parameter") | |
logging.warning(response.text) | |
elif response.status_code == 403: | |
logging.warning(f"{response.url} - IP blocked") | |
elif response.status_code == 429: | |
logging.warning(f"{response.url} - Many requests add delay") | |
elif response.status_code == 401: | |
logging.warning(f"{response.url} - Invalid token or limited") | |
else: | |
logging.warning(f"{response.url} - Server Error status_code={response.status_code}") | |
return None | |
def get_person(self, dni: str) -> Optional[dict]: | |
return self._get("/v2/reniec/dni", {"numero": dni}) | |
def get_company(self, ruc: str) -> Optional[dict]: | |
return self._get("/v2/sunat/ruc", {"numero": ruc}) | |
def get_exchange_rate(self, date: str) -> dict: | |
return self._get("/v2/sunat/tipo-cambio", {"fecha": date}) | |
def get_exchange_rate_today(self) -> dict: | |
return self._get("/v2/sunat/tipo-cambio", {}) | |
def get_exchange_rate_for_month(self, month: int, year: int) -> List[dict]: | |
return self._get("/v2/sunat/tipo-cambio", {"month": month, "year": year}) |
Tipo de cambio sunat
servicio JSON que permite acceder al tipo de cambio de la sunat de una manera mas simple:
https://apis.net.pe/api-tipo-cambio.html
- Diario o fecha especifica
- TIpo de cambio de todo el mes
para consultar DNI, como lo valido en el postman?
@BryanTorresJurado desde puedes pueder usar: GET https://api.apis.net.pe/v2/reniec/dni?numero=46027897&token=<TOKEN>
Reemplazar con el token que generas en https://apis.net.pe/app
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generar tu token en Apis.net.pe/app