Note
This project is outdated. The work was transferred to open-Mastr, where it was released in version 0.11.0. It is installable via pip:
pip install open-mastr
A python package to download the german Marktstammdatenregister (short: MaStR) and save it as a local PostgreSQL database.
The german Federal Network Agency for Electricity, Gas, Telecommunications, Post and Railway (Bundesnetzagentur) publishes their data set of all electricity and gas producers openly on their website. This data set is called Markstammdatenregister (short: MaStR). As a relatively new feature (as of 2021), they offer a complete data download in zipped xml format besides their API. The scope of the mastrsql package is to offer an easy and automated download of the MaStR into a local PostgreSQL database. It is planned to expand the package to also include an update function, that only downloads new entries which are not yet saved in the local database via the API. If you're looking for other features, also check out open-Mastr
Install PostgreSQL, either on your own or with the help of a tutorial video (for Linux). Install the software from the repository. Import the Mastr class and define a Mastr object.
>>> from mastrsql.mastr import Mastr
The postgres_standard_credentials depend on your postgres configuration. Check the given credentials before using them, otherwise an error will occure.
>>> postgres_standard_credentials = {
"dbname": "postgres",
"user": "postgres",
"password": "postgres",
"host": "localhost",
"port": "5432",
}
>>> database = Mastr(postgres_standard_credentials=postgres_standard_credentials)
Download the latest version of the zipped MaStR in xml format.
>>> database.download()
Read the downloaded files into a PostgreSQL database.
>>> database.to_sql()
For extracting information from the local PostgreSQL database we refer to other packages, for example you can use pandas.read_sql.