Skip to content
Frank Stüber edited this page Nov 12, 2024 · 8 revisions

The GV100AD file from Destatis (the German Federal Statistical Office) is part of their municipal directory system, specifically designed to provide structured data on German municipalities. This file is available in a fixed-length ASCII format, which allows for consistent data entry and processing. The GV100AD updates regularly, with monthly and quarterly releases, capturing essential information about municipalities, including geographical data and demographic statistics.

This Python library is able to parse GV100AD files and make their content easily accessible.

Installation

gv100ad-py is available on PiPy, and installation via pip is the recommended way to install:

pip install gv100ad-py

Reading example

The following example iterates through a GV100AD file and prints out all municipalities of Rhineland-Palatinate (Rheinland-Pfalz):

from gv100ad import *

# Path to the GV100AD file, please adjust.
file_path = "GV100AD_31082024.txt"

# Prints all available attributes of a Municipality object.
def print_municipality_attributes(municipality):
    print(f"Name: {municipality.name}")
    print(f"Regional Code: {municipality.regional_code}")
    print(f"Association: {municipality.association}")
    print(f"Type: {municipality.type}")
    print(f"Area: {municipality.area}")
    print(f"Inhabitants: {municipality.inhabitants}")
    print(f"Inhabitants Male: {municipality.inhabitants_male}")
    print(f"Postal Code: {municipality.postal_code}")
    print(f"Multiple Postal Codes: {municipality.multiple_postal_codes}")
    print(f"Tax Office District: {municipality.tax_office_district}")
    print(f"Higher Regional Court District: {municipality.higher_regional_court_district}")
    print(f"Regional Court District: {municipality.regional_court_district}")
    print(f"Local Court District: {municipality.local_court_district}")
    print(f"Employment Agency District: {municipality.employment_agency_district}")
    print(f"Timestamp: {municipality.timestamp}")
    print()

# Opens the GV100AD file, iterates through all records and prints the attributes only for
# municipalities of Rhineland-Palatinate
with open(file_path, 'r', encoding="utf8") as f:
    gv_reader = GV100ADReader(f)

    for record in gv_reader.read():
        if isinstance(record, Municipality) and (record.regional_code.startswith("07")):
            print_municipality_attributes(record)

Async reading example

The following example iterates asynchronously through a GV100AD file and prints out all municipalities of Rhineland-Palatinate (Rheinland-Pfalz):

import asyncio, aiofiles
from gv100ad import *

# Path to the GV100AD file, please adjust.
file_path = "GV100AD_31082024.txt"

# Prints all available attributes of a Municipality object.
def print_municipality_attributes(municipality):
    print(f"Name: {municipality.name}")
    print(f"Regional Code: {municipality.regional_code}")
    print(f"Association: {municipality.association}")
    print(f"Type: {municipality.type}")
    print(f"Area: {municipality.area}")
    print(f"Inhabitants: {municipality.inhabitants}")
    print(f"Inhabitants Male: {municipality.inhabitants_male}")
    print(f"Postal Code: {municipality.postal_code}")
    print(f"Multiple Postal Codes: {municipality.multiple_postal_codes}")
    print(f"Tax Office District: {municipality.tax_office_district}")
    print(f"Higher Regional Court District: {municipality.higher_regional_court_district}")
    print(f"Regional Court District: {municipality.regional_court_district}")
    print(f"Local Court District: {municipality.local_court_district}")
    print(f"Employment Agency District: {municipality.employment_agency_district}")
    print(f"Timestamp: {municipality.timestamp}")
    print()

# Asynchronously opens the GV100AD file, iterates through all records and prints the attributes only for
# municipalities of Rhineland-Palatinate
async def process_municipalities(file_path):
    async with aiofiles.open(file_path, 'r', encoding="utf8") as f:
        gv_reader = GV100ADReader(f)
        
        async for record in gv_reader.read_async():
            if isinstance(record, Municipality) and record.regional_code.startswith("07"):
                print_municipality_attributes(record)

# Main entry point
async def main():
    await process_municipalities(file_path)

# Runs the async main function
if __name__ == "__main__":
    asyncio.run(main())
Clone this wiki locally