Skip to main content

misocialpy

License misocialpy

Pandas-friendly Python interface to the MI Social API (Matriz de Informação Social) of the Brazilian Ministry of Development and Social Assistance (MDS/SAGI): https://aplicacoes.mds.gov.br/sagi/servicos/misocial.

A port of the R package misocialr, with the same functions, name by name, as ibgepy does with ibger. Both versions read the same field dictionary (src/misocialpy/data/dictionary.csv, a copy of misocialr/inst/extdata/) and are tested against the same recorded responses.

Theme Function Content
cadunico mds_cadunico() Cadastro Único: registered families and people, by income bracket
bolsa_familia mds_bolsa_familia() Bolsa Família programme: beneficiary families, benefits and transfers
bpc_suas mds_bpc_suas() BPC benefit and the social assistance network (CRAS, CREAS)
suas_rede mds_suas_rede() SUAS network (CadSUAS): CRAS, CREAS, Centro POP, day centres, shelters and staff per unit
suas_financiamento mds_suas_financiamento() FNAS transfers and balances of the municipal funds, and IGD-M
pbf_condicionalidades mds_pbf_condicionalidades() Education and health conditionality monitoring (SICON) and sanctions
seguranca_alimentar mds_seguranca_alimentar() PAA, Fomento Rural and cisterns

Other functions: mds_data(), mds_themes(), mds_fields(), mds_api_fields(), mds_periods(), mds_localities(), mds_drop_unpublished(), ibge_code7(), mds_clear_cache(), set_verbose().

Installation

pip install "git+https://github.com/StrategicProjects/misocial#subdirectory=misocialpy"

# or, from a local clone:
pip install ./misocialpy        # from the repository root
pip install .                   # from inside misocialpy/

Requires Python >= 3.9, pandas >= 1.3 and requests >= 2.25 (tested with pandas 1.3.5 and requests 2.25.1 on Python 3.9, and with pandas 3.0.6 on Python 3.14).

Usage

import misocialpy as m

m.mds_bolsa_familia(
    periods=[202508, 202509],
    localities=2611606,  # Recife (6 or 7 digits)
    fields=["qtd_familias_beneficiarias_bolsa_familia_i", "valor_repassado_bolsa_familia_f"],
)
#   ibge_code locality_name  period                                       field      unit       value
# 0   2611606        RECIFE  202508  qtd_familias_beneficiarias_bolsa_familia_i  Famílias    140350.0
# 1   2611606        RECIFE  202509  qtd_familias_beneficiarias_bolsa_familia_i  Famílias    139452.0
# 2   2611606        RECIFE  202508             valor_repassado_bolsa_familia_f        R$  92124240.0
# 3   2611606        RECIFE  202509             valor_repassado_bolsa_familia_f        R$  93354456.0

(Selected columns; output from 2026-10-19.)

  • periods: None (last 12 months), -n, years (2024) and/or YYYYMM.
  • localities: "BR", states ("PE" or 26), municipalities with 6 or 7 digits.

The API answers 0 for months not yet published. mds_periods() shows how many municipalities have a non-zero value in each month, and mds_drop_unpublished() explicitly removes the trailing all-zero months; reference="brazil" decides by the whole country and preserves legitimate zeros of small selections.

Validation is the same as in the R package. Invalid input is a ValidationError; an incomplete or malformed response (partial result, missing facet, total that changes while paging, repeated document, no municipality or several values) is a ResponseError; two values for the same observation are a DataConflictError; a network or HTTP failure is an HttpError (with status). All inherit from MdsError. None of this enters the cache.

mds_drop_unpublished() never deletes a non-zero value; action="flag" classifies the rows (publication_status, publication_reason, publication_reference) without removing any.

  • misocialpy.set_timeout(300): maximum time per request (default 180 s); misocialpy.set_verbose(False) hides the messages.
  • df.attrs["retrieved_at"]: date and time (UTC) of the query.
  • refresh=True in mds_periods(), mds_localities() and mds_api_fields(); mds_localities(period=) picks the month of the list. Results are copies: editing them does not change the cache.
  • misocialpy.set_cache_ttl(3600): cache validity in seconds (default: the whole session).
  • mds_fields() brings nature (estoque, fluxo, fluxo anual, acumulado, taxa, média, índice) and nature_basis; see the summing table in the R README.
  • Paging by cursorMark.
  • Queries by POST (avoids the HTTP 414 of long URLs); 3 attempts in total on 429/5xx and on connection failure, with Retry-After capped at 30 s.
  • Accepts numpy scalars (np.int64(202401)) and integer-valued numbers (26.0), as in R. Years from 2000 to the year after the current one.

Development: pip install -e ".[dev]" (pytest, responses, ruff and build); pip install -e ".[test]" for the tests only.

See the misocialr README for the notes on the fields.

Tests

pytest            # offline, with recorded fixtures
pytest -m live    # against the real API

Metadata

Release files for misocialpy 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for misocialpy 0.4.0
File Size Uploaded Provenance
misocialpy-0.4.0.tar.gz 121.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for misocialpy 0.4.0
File Interpreter ABI Platform
misocialpy-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 157.2 kB

Release files / misocialpy-0.4.0.tar.gz

Download URL misocialpy-0.4.0.tar.gz
Size 121.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8870f09443db79e3e0d05a3f0851991dd27c38862bca85199e2d1b511fc730a5
BLAKE2b-256 checksum
How to use checksums
49bb148f196f79d015cb7dc0ad47b91b78cf439ed7c5c821061b78784a668edd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / misocialpy-0.4.0-py3-none-any.whl

Download URL misocialpy-0.4.0-py3-none-any.whl
Size 36.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
339d42f05b4fa68007b560dbcaceadba33af596da92195e9f541d4ab6675e47e
BLAKE2b-256 checksum
How to use checksums
c36d13bf71ef9c5dbe0f4026d05f2146471ad2dd9a8d4ff761cf7e319b5e2851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for misocialpy 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for misocialpy-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page