@@ -38,9 +38,45 @@ def _fetch_data(
3838 show_progress : bool = True ,
3939 ** kwargs ,
4040) -> pd .DataFrame :
41- """Query, download, and concatenate Parquet files for a given dataset."""
41+ """Query, download, and concatenate Parquet files for a given dataset.
42+
43+ Internally creates an async event loop, queries the PySUS API for matching
44+ files, downloads them, and reads them into a single DataFrame.
45+
46+ Parameters
47+ ----------
48+ dataset : str
49+ Name of the dataset (e.g. ``"sinan"``, ``"sinasc"``).
50+ group : str, optional
51+ Group or disease code to filter by.
52+ state : str, optional
53+ Two-letter state abbreviation (e.g. ``"RJ"``).
54+ year : int | list[int], optional
55+ Year or list of years to fetch.
56+ month : int | list[int], optional
57+ Month or list of months to fetch.
58+ show_progress : bool, optional
59+ Whether to display a tqdm progress bar during download. Default is
60+ ``True``.
61+ **kwargs
62+ Additional arguments forwarded to :meth:`PySUS.read_parquet`.
63+
64+ Returns
65+ -------
66+ pd.DataFrame
67+ Concatenated data from all matching Parquet files. Returns an empty
68+ DataFrame when no files are found.
69+
70+ Raises
71+ ------
72+ RuntimeError
73+ If an event loop is already running but ``nest_asyncio`` is not
74+ installed.
75+ """
4276
4377 async def _fetch ():
78+ """Coroutine that performs the actual API query, download, and read."""
79+
4480 async with PySUS () as pysus :
4581 years = [year ] if isinstance (year , int ) else (year or [None ])
4682 months = [month ] if isinstance (month , int ) else (month or [None ])
@@ -157,7 +193,25 @@ def sinan(
157193 year : int | list [int ],
158194 ** kwargs ,
159195) -> pd .DataFrame :
160- """Fetch SINAN records for a given disease and year(s)."""
196+ """Fetch SINAN records for a given disease and year(s).
197+
198+ SINAN (Sistema de Informação de Agravos de Notificação) is the Brazilian
199+ notifiable-disease information system.
200+
201+ Parameters
202+ ----------
203+ disease : Literal
204+ Disease code (e.g. ``"DENG"`` for dengue, ``"ZIKA"`` for zika).
205+ year : int | list[int]
206+ Year or list of years to fetch.
207+ **kwargs
208+ Additional arguments forwarded to :func:`_fetch_data`.
209+
210+ Returns
211+ -------
212+ pd.DataFrame
213+ SINAN records for the specified disease and year(s).
214+ """
161215 return _fetch_data (
162216 dataset = "sinan" ,
163217 group = disease .upper (),
@@ -171,7 +225,27 @@ def sinasc(
171225 group : str | None = None ,
172226 ** kwargs ,
173227) -> pd .DataFrame :
174- """Fetch SINASC birth certificates for a given state, year(s), and group."""
228+ """Fetch SINASC birth certificates for a given state, year(s), and group.
229+
230+ SINASC (Sistema de Informação sobre Nascidos Vivos) is the Brazilian live
231+ birth information system.
232+
233+ Parameters
234+ ----------
235+ state : State
236+ Two-letter state abbreviation (e.g. ``"RJ"``).
237+ year : int | list[int]
238+ Year or list of years to fetch.
239+ group : str, optional
240+ Additional grouping code.
241+ **kwargs
242+ Additional arguments forwarded to :func:`_fetch_data`.
243+
244+ Returns
245+ -------
246+ pd.DataFrame
247+ SINASC birth records for the specified state, year(s), and group.
248+ """
175249 return _fetch_data (
176250 dataset = "sinasc" ,
177251 state = state .upper (),
@@ -186,7 +260,27 @@ def sim(
186260 group : str | None = None ,
187261 ** kwargs ,
188262) -> pd .DataFrame :
189- """Fetch SIM mortality records for a given state, year(s), and group."""
263+ """Fetch SIM mortality records for a given state, year(s), and group.
264+
265+ SIM (Sistema de Informação sobre Mortalidade) is the Brazilian mortality
266+ information system.
267+
268+ Parameters
269+ ----------
270+ state : State
271+ Two-letter state abbreviation (e.g. ``"RJ"``).
272+ year : int | list[int]
273+ Year or list of years to fetch.
274+ group : str, optional
275+ Additional grouping code.
276+ **kwargs
277+ Additional arguments forwarded to :func:`_fetch_data`.
278+
279+ Returns
280+ -------
281+ pd.DataFrame
282+ SIM mortality records for the specified state, year(s), and group.
283+ """
190284 return _fetch_data (
191285 dataset = "sim" ,
192286 state = state .upper (),
@@ -202,7 +296,29 @@ def sih(
202296 group : str | None = None ,
203297 ** kwargs ,
204298) -> pd .DataFrame :
205- """Fetch SIH hospital admissions for a state, year, month, and group."""
299+ """Fetch SIH hospital admissions for a state, year, month, and group.
300+
301+ SIH (Sistema de Informação Hospitalar) is the Brazilian hospital
302+ admission information system.
303+
304+ Parameters
305+ ----------
306+ state : State
307+ Two-letter state abbreviation (e.g. ``"RJ"``).
308+ year : int | list[int]
309+ Year or list of years to fetch.
310+ month : int | list[int]
311+ Month or list of months to fetch.
312+ group : str, optional
313+ Additional grouping code.
314+ **kwargs
315+ Additional arguments forwarded to :func:`_fetch_data`.
316+
317+ Returns
318+ -------
319+ pd.DataFrame
320+ SIH hospital admission records.
321+ """
206322 return _fetch_data (
207323 dataset = "sih" ,
208324 state = state .upper (),
@@ -219,7 +335,29 @@ def sia(
219335 group : str | None = None ,
220336 ** kwargs ,
221337) -> pd .DataFrame :
222- """Fetch SIA ambulatory care for a state, year, month, and group."""
338+ """Fetch SIA ambulatory care for a state, year, month, and group.
339+
340+ SIA (Sistema de Informação Ambulatorial) is the Brazilian ambulatory care
341+ information system.
342+
343+ Parameters
344+ ----------
345+ state : State
346+ Two-letter state abbreviation (e.g. ``"RJ"``).
347+ year : int | list[int]
348+ Year or list of years to fetch.
349+ month : int | list[int]
350+ Month or list of months to fetch.
351+ group : str, optional
352+ Additional grouping code.
353+ **kwargs
354+ Additional arguments forwarded to :func:`_fetch_data`.
355+
356+ Returns
357+ -------
358+ pd.DataFrame
359+ SIA ambulatory care records.
360+ """
223361 return _fetch_data (
224362 dataset = "sia" ,
225363 state = state .upper (),
@@ -235,7 +373,27 @@ def pni(
235373 group : str | None = None ,
236374 ** kwargs ,
237375) -> pd .DataFrame :
238- """Fetch PNI immunisation records for a given state, year(s), and group."""
376+ """Fetch PNI immunisation records for a given state, year(s), and group.
377+
378+ PNI (Programa Nacional de Imunizações) is the Brazilian national
379+ immunisation programme.
380+
381+ Parameters
382+ ----------
383+ state : State
384+ Two-letter state abbreviation (e.g. ``"RJ"``).
385+ year : int | list[int]
386+ Year or list of years to fetch.
387+ group : str, optional
388+ Additional grouping code.
389+ **kwargs
390+ Additional arguments forwarded to :func:`_fetch_data`.
391+
392+ Returns
393+ -------
394+ pd.DataFrame
395+ PNI immunisation records.
396+ """
239397 return _fetch_data (
240398 dataset = "pni" ,
241399 state = state .upper (),
@@ -249,7 +407,25 @@ def ibge(
249407 group : str | None = None ,
250408 ** kwargs ,
251409) -> pd .DataFrame :
252- """Fetch IBGE census data for given year(s) and optional group."""
410+ """Fetch IBGE census data for given year(s) and optional group.
411+
412+ IBGE (Instituto Brasileiro de Geografia e Estatística) provides census
413+ and demographic data.
414+
415+ Parameters
416+ ----------
417+ year : int | list[int]
418+ Year or list of years to fetch.
419+ group : str, optional
420+ Additional grouping code.
421+ **kwargs
422+ Additional arguments forwarded to :func:`_fetch_data`.
423+
424+ Returns
425+ -------
426+ pd.DataFrame
427+ IBGE census data for the specified year(s) and group.
428+ """
253429 return _fetch_data (dataset = "ibge" , group = group , year = year )
254430
255431
@@ -260,7 +436,29 @@ def cnes(
260436 group : str | None = None ,
261437 ** kwargs ,
262438) -> pd .DataFrame :
263- """Fetch CNES health facilities for a state, year, month, and group."""
439+ """Fetch CNES health facilities for a state, year, month, and group.
440+
441+ CNES (Cadastro Nacional de Estabelecimentos de Saúde) is the Brazilian
442+ registry of health-care facilities.
443+
444+ Parameters
445+ ----------
446+ state : State
447+ Two-letter state abbreviation (e.g. ``"RJ"``).
448+ year : int | list[int]
449+ Year or list of years to fetch.
450+ month : int | list[int]
451+ Month or list of months to fetch.
452+ group : str, optional
453+ Additional grouping code.
454+ **kwargs
455+ Additional arguments forwarded to :func:`_fetch_data`.
456+
457+ Returns
458+ -------
459+ pd.DataFrame
460+ CNES health-facility records.
461+ """
264462 return _fetch_data (
265463 dataset = "cnes" ,
266464 state = state .upper (),
@@ -277,7 +475,29 @@ def ciha(
277475 group : str | None = "CIHA" ,
278476 ** kwargs ,
279477) -> pd .DataFrame :
280- """Fetch CIHA hospitalisation records for state, year, month, and group."""
478+ """Fetch CIHA hospitalisation records for state, year, month, and group.
479+
480+ CIHA (Comunicação de Internação Hospitalar) provides hospitalisation
481+ records.
482+
483+ Parameters
484+ ----------
485+ state : State
486+ Two-letter state abbreviation (e.g. ``"RJ"``).
487+ year : int | list[int]
488+ Year or list of years to fetch.
489+ month : int | list[int]
490+ Month or list of months to fetch.
491+ group : str, optional
492+ Additional grouping code. Default is ``"CIHA"``.
493+ ``**kwargs``
494+ Additional arguments forwarded to :func:`_fetch_data`.
495+
496+ Returns
497+ -------
498+ pd.DataFrame
499+ CIHA hospitalisation records.
500+ """
281501 return _fetch_data (
282502 dataset = "ciha" ,
283503 state = state .upper (),
@@ -306,9 +526,39 @@ def list_files(
306526 month : int | list [int ] | None = None ,
307527 ** kwargs ,
308528) -> pd .DataFrame :
309- """List catalog files filtered by client, group, state, year, and month."""
529+ """List catalog files filtered by client, group, state, year, and month.
530+
531+ Queries the PySUS API metadata and returns a DataFrame with file name,
532+ path, dataset, group, year, month, state, and last-modified timestamp for
533+ every matching file without downloading the actual data.
534+
535+ Parameters
536+ ----------
537+ dataset : Literal
538+ Dataset name (e.g. ``"SINAN"``, ``"SINASC"``, etc.).
539+ client : Literal["FTP", "DadosGov"], optional
540+ Data source client to query.
541+ group : str, optional
542+ Group or disease code to filter by.
543+ state : str, optional
544+ Two-letter state abbreviation (e.g. ``"RJ"``).
545+ year : int | list[int], optional
546+ Year or list of years to filter by.
547+ month : int | list[int], optional
548+ Month or list of months to filter by.
549+ **kwargs
550+ Additional arguments forwarded to :meth:`PySUS.query`.
551+
552+ Returns
553+ -------
554+ pd.DataFrame
555+ DataFrame with columns ``name``, ``path``, ``dataset``, ``group``,
556+ ``year``, ``month``, ``state``, and ``modify``.
557+ """
310558
311559 async def _list ():
560+ """Coroutine that queries the PySUS API and builds the file list."""
561+
312562 async with PySUS () as pysus :
313563 years = [year ] if isinstance (year , int ) else (year or [None ])
314564 months = [month ] if isinstance (month , int ) else (month or [None ])
0 commit comments