tukan-python 0.3.0__tar.gz → 0.3.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tukan_python
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: SDK de Python para acceder a datos oficiales de México a través de la API de Tukan.
5
5
  Author-email: TukanMx <contacto@tukanmx.com>
6
6
  License-Expression: MIT
@@ -300,6 +300,43 @@ q.set_table_name("mex_cnbv_cb_orig_by_gender_monthly")
300
300
  resultado = q.execute_query()
301
301
  ```
302
302
 
303
+ ### 7. Consultas SQL con `SQLQuery`
304
+
305
+ Si prefieres escribir SQL directamente, puedes usar la clase `SQLQuery`. Las consultas se ejecutan con el motor Blizzard y la paginación se maneja automáticamente:
306
+
307
+ ```python
308
+ from tukan_python import SQLQuery
309
+
310
+ sq = SQLQuery(sql="""
311
+ SELECT
312
+ END_DATE AS end_date,
313
+ INSTITUTIONS_REF AS institutions,
314
+ INSTITUTIONS_NAME AS institutions__name,
315
+ INDICATOR_REF AS indicator,
316
+ INDICATOR_NAME AS indicator__name,
317
+ VALUE as value
318
+ FROM tukan_db.source_of_truth_full.mex_tukan_retail_sales_by_company
319
+ WHERE END_DATE = '2022-12-31'
320
+ LIMIT 100000 OFFSET 0
321
+ """)
322
+
323
+ resultado = sq.execute()
324
+ print(resultado["df"])
325
+ ```
326
+
327
+ Las tablas disponibles en SQL se encuentran en el esquema `tukan_db.source_of_truth_full`.
328
+
329
+ #### Guardar una consulta SQL en tu perfil
330
+
331
+ Puedes guardar tus consultas SQL para acceder a ellas desde la [aplicación web](https://app.tukanmx.com):
332
+
333
+ ```python
334
+ sq = SQLQuery(sql="SELECT * FROM tukan_db.source_of_truth_full.mex_banxico_cf102 LIMIT 100")
335
+ sq.save_sql_query(name="Tipo de cambio FIX", language="es")
336
+ ```
337
+
338
+ Parámetros opcionales: `description`, `tags` (lista de strings).
339
+
303
340
  ## Conceptos clave
304
341
 
305
342
  ### Tablas
@@ -272,6 +272,43 @@ q.set_table_name("mex_cnbv_cb_orig_by_gender_monthly")
272
272
  resultado = q.execute_query()
273
273
  ```
274
274
 
275
+ ### 7. Consultas SQL con `SQLQuery`
276
+
277
+ Si prefieres escribir SQL directamente, puedes usar la clase `SQLQuery`. Las consultas se ejecutan con el motor Blizzard y la paginación se maneja automáticamente:
278
+
279
+ ```python
280
+ from tukan_python import SQLQuery
281
+
282
+ sq = SQLQuery(sql="""
283
+ SELECT
284
+ END_DATE AS end_date,
285
+ INSTITUTIONS_REF AS institutions,
286
+ INSTITUTIONS_NAME AS institutions__name,
287
+ INDICATOR_REF AS indicator,
288
+ INDICATOR_NAME AS indicator__name,
289
+ VALUE as value
290
+ FROM tukan_db.source_of_truth_full.mex_tukan_retail_sales_by_company
291
+ WHERE END_DATE = '2022-12-31'
292
+ LIMIT 100000 OFFSET 0
293
+ """)
294
+
295
+ resultado = sq.execute()
296
+ print(resultado["df"])
297
+ ```
298
+
299
+ Las tablas disponibles en SQL se encuentran en el esquema `tukan_db.source_of_truth_full`.
300
+
301
+ #### Guardar una consulta SQL en tu perfil
302
+
303
+ Puedes guardar tus consultas SQL para acceder a ellas desde la [aplicación web](https://app.tukanmx.com):
304
+
305
+ ```python
306
+ sq = SQLQuery(sql="SELECT * FROM tukan_db.source_of_truth_full.mex_banxico_cf102 LIMIT 100")
307
+ sq.save_sql_query(name="Tipo de cambio FIX", language="es")
308
+ ```
309
+
310
+ Parámetros opcionales: `description`, `tags` (lista de strings).
311
+
275
312
  ## Conceptos clave
276
313
 
277
314
  ### Tablas
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tukan_python"
7
- version = "0.3.0"
7
+ version = "0.3.1"
8
8
  description = "SDK de Python para acceder a datos oficiales de México a través de la API de Tukan."
9
9
  authors = [
10
10
  { name = "TukanMx", email = "contacto@tukanmx.com" }
@@ -287,6 +287,39 @@ class SQLQuery:
287
287
  instance._sql = sql
288
288
  return instance
289
289
 
290
+ def save_sql_query(
291
+ self,
292
+ name: str,
293
+ language: str = "es",
294
+ description: str = "",
295
+ tags: Optional[list[str]] = None,
296
+ ) -> dict:
297
+ """Save this SQL query to the user's profile.
298
+
299
+ Args:
300
+ name: Display name for the saved query.
301
+ language: Language code (default "es").
302
+ description: Optional description.
303
+ tags: Optional list of tag strings.
304
+
305
+ Returns:
306
+ API response dict.
307
+ """
308
+ body = {
309
+ "name": name,
310
+ "description": description,
311
+ "language": language,
312
+ "query": {
313
+ "name": name,
314
+ "raw_sql": self._encode_sql(),
315
+ "language": language,
316
+ "retrieve_engine": "blizzard",
317
+ "use_vertical_mode": False,
318
+ },
319
+ "tags": tags if tags is not None else [],
320
+ }
321
+ return self.tukan.execute_post_operation(body, "visualizations/query/")
322
+
290
323
  def __str__(self) -> str:
291
324
  return f"SQLQuery(sql={self._sql!r})"
292
325
 
@@ -198,6 +198,53 @@ class Tukan:
198
198
  return df
199
199
 
200
200
 
201
+ def get_catalog_tables(
202
+ self, page: int = 1, page_size: int = 40, language: str = "es"
203
+ ) -> list[dict]:
204
+ """List available catalog tables.
205
+
206
+ Args:
207
+ page: Page number (1-indexed).
208
+ page_size: Number of results per page.
209
+ language: Language code ('es' or 'en').
210
+
211
+ Returns:
212
+ List of catalog table dicts.
213
+ """
214
+ url = f"{self.env}data/catalogue_table/"
215
+ headers = {"Authorization": f"token {self.token}"}
216
+ params = {
217
+ "page_size": page_size,
218
+ "current": page,
219
+ "api": "data",
220
+ "resource": "catalogue_table",
221
+ "language": language,
222
+ }
223
+ request_partial = wrapped_partial(
224
+ requests.get, url=url, headers=headers, params=params, timeout=30
225
+ )
226
+ response = self.persistent_request(request_partial)
227
+ if response.status_code >= 300:
228
+ raise Exception(f"Failed to list catalog tables: {response.text}")
229
+ return response.json()
230
+
231
+ def export_catalog_table(self, catalogue_id: str) -> pd.DataFrame:
232
+ """Export a catalog table as a DataFrame.
233
+
234
+ Args:
235
+ catalogue_id: The catalog table ID to export.
236
+
237
+ Returns:
238
+ DataFrame with the catalog table data.
239
+ """
240
+ url = f"{self.env}data/retrieve_json_catalogue/{catalogue_id}/{self.token}/"
241
+ request_partial = wrapped_partial(requests.get, url=url, timeout=30)
242
+ response = self.persistent_request(request_partial)
243
+ if response.status_code >= 300:
244
+ raise Exception(f"Failed to export catalog table: {response.text}")
245
+ data = response.json()
246
+ return pd.DataFrame(data)
247
+
201
248
  def sql(self, query: str) -> dict:
202
249
  """Execute a raw SQL query against the Tukan API.
203
250
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tukan_python
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: SDK de Python para acceder a datos oficiales de México a través de la API de Tukan.
5
5
  Author-email: TukanMx <contacto@tukanmx.com>
6
6
  License-Expression: MIT
@@ -300,6 +300,43 @@ q.set_table_name("mex_cnbv_cb_orig_by_gender_monthly")
300
300
  resultado = q.execute_query()
301
301
  ```
302
302
 
303
+ ### 7. Consultas SQL con `SQLQuery`
304
+
305
+ Si prefieres escribir SQL directamente, puedes usar la clase `SQLQuery`. Las consultas se ejecutan con el motor Blizzard y la paginación se maneja automáticamente:
306
+
307
+ ```python
308
+ from tukan_python import SQLQuery
309
+
310
+ sq = SQLQuery(sql="""
311
+ SELECT
312
+ END_DATE AS end_date,
313
+ INSTITUTIONS_REF AS institutions,
314
+ INSTITUTIONS_NAME AS institutions__name,
315
+ INDICATOR_REF AS indicator,
316
+ INDICATOR_NAME AS indicator__name,
317
+ VALUE as value
318
+ FROM tukan_db.source_of_truth_full.mex_tukan_retail_sales_by_company
319
+ WHERE END_DATE = '2022-12-31'
320
+ LIMIT 100000 OFFSET 0
321
+ """)
322
+
323
+ resultado = sq.execute()
324
+ print(resultado["df"])
325
+ ```
326
+
327
+ Las tablas disponibles en SQL se encuentran en el esquema `tukan_db.source_of_truth_full`.
328
+
329
+ #### Guardar una consulta SQL en tu perfil
330
+
331
+ Puedes guardar tus consultas SQL para acceder a ellas desde la [aplicación web](https://app.tukanmx.com):
332
+
333
+ ```python
334
+ sq = SQLQuery(sql="SELECT * FROM tukan_db.source_of_truth_full.mex_banxico_cf102 LIMIT 100")
335
+ sq.save_sql_query(name="Tipo de cambio FIX", language="es")
336
+ ```
337
+
338
+ Parámetros opcionales: `description`, `tags` (lista de strings).
339
+
303
340
  ## Conceptos clave
304
341
 
305
342
  ### Tablas
File without changes
File without changes