Validate, calculate and obtain CURP information in México.
Project description
ValidaCurp Python Client
-
This library can validate, calculate and obtain CURP information in México.
-
Copyright (c) Multiservicios Web JCA S.A. de C.V., https://multiservicios-web.com.mx
-
More information: https://valida-curp.com.mx
-
License: MIT (https://opensource.org/license/MIT)
1. Requirements
- Python 3.7 or later
- Instalación automática de dependencias (
requestsypython-dotenv)
2. Installation
You can install this package via pip:
pip install multiserviciosweb
3. Account
3.1. Create an account
Create an account following this link: https://valida-curp.com.mx/registro
3.2. Create a project
Create a project following this link: https://valida-curp.com.mx/proyectos/crear
3.3. Get token
Get your token from project dashboard: https://valida-curp.com.mx/proyectos
4. Usage
4.1. Import library
from MultiServiciosWeb import ValidaCurp, ValidaCurpException
4.2. Create instance
You can provide token in 3 ways:
# Option 1: Directly in constructor
valida_curp = ValidaCurp('YOUR-TOKEN')
# Option 2: Environment variable (.env file)
# .env content:
# TOKEN_VALIDA_API_CURP = 'YOUR-TOKEN'
valida_curp = ValidaCurp()
# Option 3: System environment variable
# export TOKEN_VALIDA_API_CURP='YOUR-TOKEN'
valida_curp = ValidaCurp()
4.3. (Optional) Set API Version
You can set the API version (1 or 2). Default is 2:
valida_curp.set_version(2) # 1 for legacy, 2 for current
4.4. (Optional) Custom Endpoint
valida_curp = ValidaCurp(
token='YOUR-TOKEN',
custom_endpoint='https://custom.valida-curp.com.mx/'
)
5. Methods
5.1. Validate CURP
validation_result = valida_curp.is_valid('BUME980528HDFRCD02')
print(validation_result)
# Output: {'valido': True} or {'valido': False}
5.2. Get CURP data
curp_data = valida_curp.get_data('BUME980528HDFRCD02')
print(curp_data)
# Output: Dictionary with CURP information
5.3. Calculate CURP
person_data = {
'names': 'Juan Carlos',
'lastName': 'García',
'secondLastName': 'López',
'birthDay': '15',
'birthMonth': '08',
'birthYear': '1990',
'gender': 'H', # H: Hombre, M: Mujer
'entity': '09' # CDMX
}
result = valida_curp.calculate(person_data)
print(result)
# Output: {'curp': 'GALJ900815HDFRPN01'}
5.4. Get entities
entities = valida_curp.get_entities()
print(entities)
# Output: Dictionary with all Mexican states and codes
6. Full Example
from MultiServiciosWeb import ValidaCurp, ValidaCurpException
try:
# Initialize client
valida_curp = ValidaCurp('YOUR-TOKEN')
# 1. Validate CURP
print("Validating CURP:", valida_curp.is_valid('BUME980528HDFRCD02'))
# 2. Get CURP data
print("CURP data:", valida_curp.get_data('BUME980528HDFRCD02'))
# 3. Calculate CURP
person_data = {
'names': 'María Fernanda',
'lastName': 'Hernández',
'secondLastName': 'Jiménez',
'birthDay': '22',
'birthMonth': '11',
'birthYear': '1985',
'gender': 'M',
'entity': '14' # Jalisco
}
print("Calculated CURP:", valida_curp.calculate(person_data))
# 4. Get entities
print("Entities:", valida_curp.get_entities())
# 5. Switch to API v1
valida_curp.set_version(1)
print("Entities (v1):", valida_curp.get_entities())
except ValidaCurpException as e:
print(f"API Error: {e}")
except Exception as e:
print(f"General Error: {e}")
7. Error Handling
Handle specific errors:
try:
valida_curp.get_data('INVALID-CURP')
except ValidaCurpException as e:
if "Authentication" in str(e):
print("Check your token")
elif "Bad request" in str(e):
print("Invalid parameters")
else:
print(f"API Error: {e}")
8. Support
For support, please contact:
- Email: soporte@multiservicios-web.com.mx
- Website: https://valida-curp.com.mx/soporte
9. License
This project is licensed under the MIT License - see the LICENSE file for details.
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 multiserviciosweb-1.1.1.tar.gz.
File metadata
- Download URL: multiserviciosweb-1.1.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d119b0f756b8c2f46accf3645bbfc84e2a843baa9aae8aee6021b3ab9ad764ec
|
|
| MD5 |
d8a2971bbb0407c1bab99cf83bd234a8
|
|
| BLAKE2b-256 |
354b28dae6829b6e37f625ba200e2ef2f39d60f38e7f7745051448d385926826
|
File details
Details for the file multiserviciosweb-1.1.1-py3-none-any.whl.
File metadata
- Download URL: multiserviciosweb-1.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
059713b1bb85d4e988dd8855af05491edd37c53ff44b803d287b5c2bb6975ac2
|
|
| MD5 |
36c695f50a4785d49d325e61902a6cbc
|
|
| BLAKE2b-256 |
9106ad429c730db35dc62167cfa5fae0e8354dc3f05f5ec97324f982cf89be76
|