FTP
pysus.api.ftp.client.FTP browses the legacy DATASUS FTP server
(ftp.datasus.gov.br) — the complete historical archive: per-UF,
per-month .dbc files for every system.
Connecting
Anonymous access, no credentials:
import asyncio
from pysus.api.ftp.client import FTP
async def main():
ftp = FTP()
await ftp.connect()
try:
...
finally:
await ftp.close()
Listing datasets and files
datasets = await ftp.datasets() # CIHA, CNES, IBGE, PNI, SIA, SIH, SIM, SINAN, SINASC
sinan = next(d for d in datasets if d.name == "SINAN")
content = await sinan.content # groups (DENG, CHIK, ...) and directories
Each file carries parsed metadata (group, state, year, month) extracted from the DATASUS filename conventions:
for item in content:
for file in await item.files:
print(file.name, file.size, file.modify, file.year, file.month, file.state)
Searching
search filters files by any
attribute:
files = await sinan.search(group="DENG", year=2024)
Downloading
local = await file.download() # downloads to the PySUS cache
df = await local.load() # parses the DBC into a DataFrame
download() returns a wrapper (e.g. pysus.api.extensions.DBC)
that decompresses and parses the legacy format on load.