apiempresas 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: apiempresas
3
+ Version: 1.0.0
4
+ Summary: SDK oficial de APIEmpresas.es para Python
5
+ Home-page: https://apiempresas.es
6
+ Author: APIEmpresas
7
+ Author-email: soporte@apiempresas.es
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.7
11
+ Requires-Dist: requests>=2.0.0
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: classifier
15
+ Dynamic: home-page
16
+ Dynamic: requires-dist
17
+ Dynamic: requires-python
18
+ Dynamic: summary
@@ -0,0 +1,4 @@
1
+ from .client import ApiEmpresas
2
+ from .exceptions import ApiError
3
+
4
+ __all__ = ["ApiEmpresas", "ApiError"]
@@ -0,0 +1,69 @@
1
+ import requests
2
+ from .exceptions import ApiError
3
+ from .resources.companies import Companies
4
+
5
+ class ApiEmpresas:
6
+ """
7
+ Cliente principal para interactuar con la API de APIEmpresas.es
8
+ """
9
+ def __init__(self, api_key: str, base_url: str = 'https://apiempresas.es/api/v1', timeout: int = 30):
10
+ if not api_key or not api_key.strip():
11
+ raise ApiError("La propiedad 'api_key' es obligatoria para inicializar ApiEmpresas.", status=401)
12
+
13
+ self.api_key = api_key
14
+ self.base_url = base_url.rstrip('/')
15
+ self.timeout = timeout
16
+
17
+ # Iniciar sesión de requests para reutilizar conexiones
18
+ self.session = requests.Session()
19
+ self.session.headers.update({
20
+ 'X-API-KEY': self.api_key,
21
+ 'Accept': 'application/json',
22
+ })
23
+
24
+ # Inicializar recursos
25
+ self.companies = Companies(self)
26
+
27
+ def request(self, method: str, endpoint: str, params: dict = None, json_data: dict = None) -> dict:
28
+ """
29
+ Método interno genérico para lanzar las peticiones HTTP.
30
+ """
31
+ url = f"{self.base_url}{endpoint}"
32
+
33
+ try:
34
+ response = self.session.request(
35
+ method=method,
36
+ url=url,
37
+ params=params,
38
+ json=json_data,
39
+ timeout=self.timeout
40
+ )
41
+ except requests.exceptions.RequestException as e:
42
+ raise ApiError(f"Error de red al conectar con APIEmpresas: {str(e)}", status=500)
43
+
44
+ try:
45
+ decoded_data = response.json()
46
+ except ValueError:
47
+ decoded_data = None
48
+
49
+ if not response.ok:
50
+ status = response.status_code
51
+ message = f"{status} Error desconocido en la API"
52
+ error_code = None
53
+
54
+ if decoded_data and isinstance(decoded_data, dict):
55
+ message = decoded_data.get('message', message)
56
+ error_code = decoded_data.get('error')
57
+ else:
58
+ message = response.text
59
+
60
+ raise ApiError(message, status=status, error_code=error_code, raw_data=decoded_data)
61
+
62
+ if decoded_data and 'data' in decoded_data:
63
+ # Para el endpoint /batch, se suele devolver meta y data
64
+ if 'meta' in decoded_data:
65
+ return decoded_data
66
+ return decoded_data['data']
67
+
68
+ return decoded_data
69
+
@@ -0,0 +1,9 @@
1
+ class ApiError(Exception):
2
+ """
3
+ Excepción lanzada cuando la API de APIEmpresas devuelve un error.
4
+ """
5
+ def __init__(self, message: str, status: int = 500, error_code: str = None, raw_data: dict = None):
6
+ super().__init__(message)
7
+ self.status = status
8
+ self.error_code = error_code
9
+ self.raw_data = raw_data
@@ -0,0 +1 @@
1
+ # vacio
@@ -0,0 +1,47 @@
1
+ class Companies:
2
+ def __init__(self, client):
3
+ self._client = client
4
+
5
+ def get(self, cif: str) -> dict:
6
+ """Obtiene los datos básicos de una empresa por su CIF."""
7
+ return self._client.request('GET', '/companies', params={'cif': cif})
8
+
9
+ def search(self, q: str) -> dict:
10
+ """Busca empresas por nombre o razón social."""
11
+ return self._client.request('GET', '/companies/search', params={'q': q})
12
+
13
+ def batch(self, cifs: list) -> dict:
14
+ """Consulta múltiple de CIFs en una sola petición."""
15
+ return self._client.request('POST', '/companies/batch', json_data={'cifs': cifs})
16
+
17
+ def score(self, cif: str) -> dict:
18
+ """(Pro) Obtiene el Scoring Comercial de una empresa."""
19
+ return self._client.request('GET', '/companies/score', params={'cif': cif})
20
+
21
+ def borme(self, cif: str) -> dict:
22
+ """(Pro) Obtiene el historial de actos del BORME de una empresa."""
23
+ return self._client.request('GET', '/companies/borme', params={'cif': cif})
24
+
25
+ def signals(self, cif: str) -> dict:
26
+ """(Pro) Obtiene las señales societarias recientes de una empresa."""
27
+ return self._client.request('GET', '/companies/signals', params={'cif': cif})
28
+
29
+ def insights(self, cif: str) -> dict:
30
+ """(Business) Obtiene Insights IA de una empresa."""
31
+ return self._client.request('GET', '/companies/insights', params={'cif': cif})
32
+
33
+ def contact_prep(self, cif: str) -> dict:
34
+ """(Pro) Obtiene datos de contacto y preparación de la empresa."""
35
+ return self._client.request('GET', '/companies/contact-prep', params={'cif': cif})
36
+
37
+ def radar(self, cif: str) -> dict:
38
+ """(Business) Obtiene la información del Radar de empresas."""
39
+ return self._client.request('GET', '/companies/radar', params={'cif': cif})
40
+
41
+ def match(self, cif: str) -> dict:
42
+ """(Business) Realiza un match avanzado con los datos de una empresa."""
43
+ return self._client.request('GET', '/companies/match', params={'cif': cif})
44
+
45
+ def network(self, cif: str) -> dict:
46
+ """(Business) Obtiene la red o entramado societario (Network) de una empresa."""
47
+ return self._client.request('GET', '/companies/network', params={'cif': cif})
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: apiempresas
3
+ Version: 1.0.0
4
+ Summary: SDK oficial de APIEmpresas.es para Python
5
+ Home-page: https://apiempresas.es
6
+ Author: APIEmpresas
7
+ Author-email: soporte@apiempresas.es
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.7
11
+ Requires-Dist: requests>=2.0.0
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: classifier
15
+ Dynamic: home-page
16
+ Dynamic: requires-dist
17
+ Dynamic: requires-python
18
+ Dynamic: summary
@@ -0,0 +1,12 @@
1
+ setup.py
2
+ apiempresas/__init__.py
3
+ apiempresas/client.py
4
+ apiempresas/exceptions.py
5
+ apiempresas.egg-info/PKG-INFO
6
+ apiempresas.egg-info/SOURCES.txt
7
+ apiempresas.egg-info/dependency_links.txt
8
+ apiempresas.egg-info/requires.txt
9
+ apiempresas.egg-info/top_level.txt
10
+ apiempresas/resources/__init__.py
11
+ apiempresas/resources/companies.py
12
+ tests/test_apiempresas.py
@@ -0,0 +1 @@
1
+ requests>=2.0.0
@@ -0,0 +1 @@
1
+ apiempresas
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="apiempresas",
5
+ version="1.0.0",
6
+ description="SDK oficial de APIEmpresas.es para Python",
7
+ author="APIEmpresas",
8
+ author_email="soporte@apiempresas.es",
9
+ url="https://apiempresas.es",
10
+ packages=find_packages(),
11
+ install_requires=[
12
+ "requests>=2.0.0",
13
+ ],
14
+ classifiers=[
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ],
18
+ python_requires=">=3.7",
19
+ )
@@ -0,0 +1,16 @@
1
+ import unittest
2
+ from apiempresas import ApiEmpresas, ApiError
3
+
4
+ class TestApiEmpresas(unittest.TestCase):
5
+ def test_missing_api_key(self):
6
+ with self.assertRaises(ApiError) as context:
7
+ ApiEmpresas('')
8
+ self.assertTrue('obligatoria' in str(context.exception))
9
+
10
+ def test_init_success(self):
11
+ client = ApiEmpresas('fake_key')
12
+ self.assertEqual(client.api_key, 'fake_key')
13
+ self.assertEqual(client.session.headers['X-API-KEY'], 'fake_key')
14
+
15
+ if __name__ == '__main__':
16
+ unittest.main()