Skip to main content

alepe

PyPI Python tests License: MIT DOI

Tidy access from Python to the open data API of the Legislative Assembly of the State of Pernambuco, Brazil (ALEPE): representatives, staff, positions, departments, remuneration, contracts, procurement and legislative propositions — as pandas frames with clean names and parsed types.

This is the Python sibling of the R package alepe; both wrap the same endpoints and produce the same column names.

Installation

pip install alepe

Quick start

import alepe

# Current representatives
alepe.representatives()

# Permanent staff, largest departments
alepe.staff(status="permanent").value_counts("nome_lotacao")

# Contracts active today
import datetime as dt
today = dt.date.today()
contracts = alepe.contracts()
contracts[(contracts.vigencia_inicio <= today) & (contracts.vigencia_fim >= today)]

# Bills of a given year
alepe.bills(year=2024)

Column names keep the official Portuguese field names, normalised to snake_case, so a result stays traceable to its source. Filter values accept both vocabularies — status="permanent" and status="efetivo" are the same query.

Em português

Cada função tem um alias com o nome do próprio endpoint da API, para quem prefere manter o pipeline inteiro em português:

alepe.parlamentares()
alepe.servidores(status="efetivo")
alepe.contratos()
alepe.projetos(ano=2024)

cargos(), lotacoes(), remuneracao(), licitacoes(), indicacoes(), requerimentos() e limpar_cache() completam o conjunto.

How it works

Every function is a thin wrapper over the same core: a cached, retrying request whose response is typed into a frame by a documented schema.

A call goes through the request builder, which adds the user agent, a 60 second timeout, a six-hour cache and retries, then performs the request against the ALEPE API. A 2xx response is parsed and typed into a frame; a timeout or an error surviving the retries raises AlepeHTTPError.

What the package handles for you

The API is generated from an internal system and shows it. Three quirks would otherwise produce quietly wrong numbers:

  • Two naming conventions at once. NOME_LOTACAO from /servidores, nomeParlamentar from /parlamentares. Both become nome_lotacao and nome_parlamentar.
  • Two number encodings at once. "1.234,56" in some fields and float-formatted strings such as "119267.04" in others. Reading either with a fixed locale corrupts the other — a Brazilian locale turns 119267.04 into 11 926 704. The parser decides per value.
  • Dates in three shapes, including serialised DateTime objects ({"date": "2026-05-05 00:00:00.000000", ...}).

The propositions endpoints answer XML embedded in CSV; the package parses it into ordinary columns and strips the HTML markup out of the free-text fields.

Caching, retries and failures

Responses are cached for six hours in the session's temporary directory. Set ALEPE_CACHE_DIR, or call alepe.cache_dir(path), to keep them between sessions; alepe.cache_clear() empties it, and any call takes refresh=True to bypass it.

Requests are retried up to three times on 429 and 5xx with exponential backoff, with a 60-second timeout. That default is measured, not habitual: /licitacoes regularly takes 25–30 seconds to answer, and the service cuts its own query off at 30 seconds, so a 30-second client timeout fails on margin alone.

When the API cannot be reached, the call raises AlepeHTTPError, carrying the status code and the URL. This is where the two siblings differ on purpose: CRAN's policy on internet resources requires the R package to warn and return an empty result instead of stopping, while a silent empty frame would be surprising in Python.

try:
    frame = alepe.procurements()
except alepe.AlepeHTTPError as err:
    print(f"ALEPE is not answering ({err.status}); carrying on without it")
    frame = alepe.empty("procurements")

alepe.empty(name) returns a correctly typed empty frame for any endpoint, which is what you want when a pipeline downstream expects the columns to exist either way.

Part of a family of clients for Brazilian public data published under StrategicProjects, with siblings in R on CRAN: tceper (Pernambuco Court of Accounts), transferegovr and its Python twin transferegovpy, tesouror, comexr, datasusr, ibger and pixr.

Citation

Archived on Zenodo. The DOI above is the concept DOI: it always resolves to the latest version. To cite the exact version you used, take its own DOI from the Zenodo record, or read CITATION.cff.

License

MIT.

Metadata

Release files for alepe 0.1.2

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

Source distribution (sdist)

Source distribution for alepe 0.1.2
File Size Uploaded
alepe-0.1.2.tar.gz 24.5 kB Details

Built distribution (wheel)

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

Total release size: 43.4 kB

Release files / alepe-0.1.2.tar.gz

Download URL alepe-0.1.2.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
87747f542534fbaa3d5168be315fb40b15d3723f39bdf80fc3d057dc1c6ba14d
BLAKE2b-256 checksum
How to use checksums
e86b5680f895a06049c0493bf30f020519b0b10ecad2ffcba6b0b4bb699970a3
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 Sep 29, 2026.

Transparency log

Release files / alepe-0.1.2-py3-none-any.whl

Download URL alepe-0.1.2-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9440c7ea04eb79256c4c4071b594a6f0fcbbba160805a918c9bebb1d7ac3543
BLAKE2b-256 checksum
How to use checksums
fa74c582ec63eb838281a98395a4079973b06a51cf64f166f4fc6d439a1db7e4
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 Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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