Skip to main content

Python wrapper for the official Bundestag-API

Project description

Upload Python Package

Bundestag-API

A wrapper for the official Bundestag (German Federal Parliament) API in Python. It aim is to make querying the API a little easier in Python and relieve you from writing a lot of boilerplate code.

It currently doesn't encompass a 100% of the lastest API parameters (see To-Do section) but aims to do so shortly.

The official information on the API can be found here: Bundestag.de

Installation

Pip install (recommended)

$ pip install bundestag_api

Install from source

$ git clone https://github.com/jschibberges/Bundestag-API.git
$ cd Bundestag-API
$ pip install -r requirements.txt

Setup

The API requires a key to authenticate requests. Personal key can be requested from the Bundestag administration. However a general API key has been published that is valid until May 31st 2024. This key is automatically used until that date when no other key is supplied by the user.

Usage

To save your API key create a connection-object, that you can then pass to the search functions. It will save you time, should you have to change API keys at a later date. If you don't supply an API key, the official API key will be used until 31st of May 2025.

import bundestag_api
bta = bundestag_api.btaConnection() #if you want to use your own API key, supply it via "apikey="XXX")
data = bta.search_document()
for d in data:
    print(d["drucksachetyp"]+": "+d["titel"])

The query-function serves as a general search function that can be used to query all resources of the API. However, you will also have to specify all relevant parameters for your search. Data is returned as a dictionary (which can easily be saved as json). Minimally the resource type needs to specified.

For each resource type the api offers a search function and a get function are implemented. Get functions retrieve data for specific entity ids while search function offer all parameters that are relevant to the resource type. Example for documents (Drucksachen):

bta.search_document(datestart="2022-11-01",dateend="2022-11-01",institution="BT")
bta.get_document(btid=264030)

The Bundestag API serves 8 different resources though 2 are doubled with the only difference being whether the document text is returned via the API.

Activities ("Aktivität")

Get one or more activities by their ID

bta.get_activity(btid)

Search for documents by specifying parameters for start and end date or institution. Important: The standard number of entities returned are 100. If more are desired, the "num" parameter must be set.

bta.search_activity()

Documents / Full-Text ("Drucksache")

Get one or more documents by their ID

bta.get_document(btid)

Search for documents by specifying parameters for start and end date or institution. Important: The standard number of entities returned are 100. If more are desired, the "num" parameter must be set.

bta.search_document()

"fulltext=True" can be passed as parameter to retrieve the full text of the document (if available). It defaults to False.

Persons ("Person")

Get one or more persons by their ID

bta.get_person(btid)

Search for persons by specifying parameters for start and end date or institution. Important: The standard number of entities returned are 100. If more are desired, the "num" parameter must be set.

bta.search_person()

Plenary Protocols / Full-Text ("Plenarprotokoll")

Get one or more plenary protocols by their ID

bta.get_plenaryprotocol(btid)

Search for plenary protocols by specifying parameters for start and end date or institution. Important: The standard number of entities returned are 100. If more are desired, the "num" parameter must be set.

bta.search_plenaryprotocol()

"fulltext=True" can be passed as parameter to retrieve the full text of the plenary protocols (if available). It defaults to False.

Procedures ("Vorgang")

Get one or more procedures by their ID

bta.get_procedure(btid)

Search for procedures by specifying parameters for start and end date or institution. Important: The standard number of entities returned are 100. If more are desired, the "num" parameter must be set.

bta.search_procedure()

Procedure Positions ("Vorgangsposition")

Get one or more procedure positions by their ID

bta.get_procedure(btid)

Search for procedure positions by specifying parameters for start and end date or institution. Important: The standard number of entities returned are 100. If more are desired, the "num" parameter must be set.

bta.search_procedure()

ToDo's

  • Implement filters for GESTA-Number, Beratungsstand, Fundstelle, Initiative, Ressort (federführend), Verkündungsblatt_Kürzel, Vorgangstyp, Vorgangstyp-Notation
  • Implement retries before failure
  • Implement sufficient unit tests
  • Implement more extensive logging
  • Parallelize requests for larger queries
  • Extend Class methods

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bundestag_api-1.0.8.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

bundestag_api-1.0.8-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file bundestag_api-1.0.8.tar.gz.

File metadata

  • Download URL: bundestag_api-1.0.8.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for bundestag_api-1.0.8.tar.gz
Algorithm Hash digest
SHA256 7fc76fb0c3f227579dbceb4caeaa269a419697a20962e06f7a604d7e9b68fc57
MD5 6d734b550c04c9dec3cbdc9bf756e878
BLAKE2b-256 4f3332417cc07cbc25d2f31f62641b4e36a9be7cb4e06f9f5989a15c3585e23d

See more details on using hashes here.

File details

Details for the file bundestag_api-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for bundestag_api-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d77220d3b6ce2bbcec542de7f4e26c9348107c2d436739740f8cef211ce0f8c2
MD5 63a1a3d2a97529dabbcfc80faeb336e4
BLAKE2b-256 f4516498b90521e0a4075a91cced7235907acd2872d402b98696e051b672773b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page