Skip to main content

Client for OpenData DKAN-API

Project description

opencity

opencity is an interface for the open data portal of Constance. It allows you to directly inspect, download, and work with the available data. This package can be easily used by practitioners, members of the civil society, and academics. Technically, it relies on the DKAN API.

Capabilities

  • get an overview of data sets via show_data()
  • load data directly into Python via get_data()
  • download data sets onto your local machine via save_data()

Generally, each functionality can be filtered by names and tags of the different data sets and returns pandas.DataFrames.

class opencity.OpenCity(cf = None)

class with several features described in the following

Properties :

  • formats
    list of Strings specifying formats
  • cf
    reference to configuration file containing all relevant information
  • (various) helper classes
    reference to various files containing helper classes

Functions :

  • show_data()
  • get_data()
  • save_data()

Each functionality is described in the following in detail.

OpenCity.show_data(data=[], tag=False, overview=False, meta=False, terminal=False)

displays an overview of the available and indicated data sets to the terminal or as a popup

Parameters:

  • data: list of Strings, default: empty list
    containing names or tags
  • tag: Boolean, default: False
    set to True if data list contains tags
  • overview: Boolean, default: False
    set to True if a short overview of the data sets (title, short name, tags) is desired in the console
  • meta: Boolean, default: False
    set to True if more detailed information on the data sets is desired depending on parameter 'terminal'
  • terminal: Boolean, default: False
    set to True if meta data should be printed in the console instead of a popup

Returns: void

OpenCity.get_data(data=[], tag=False, meta=False)

retrieves the indicated data from the open data portal of Constance

Parameters:

  • data: list of Strings, default: empty list
    containing names or tags
  • tag: Boolean, default: False
    set to True if data list contains tags
  • meta : Boolean, default: False
    set to True if meta data should be returned

Returns: pandas.DataFrame | dict containing pandas.DataFrames

OpenCity.save_data(data, tag=False, folder="")

saves the indicated data to the local disk

Parameters:

  • data: list of Strings
    containing names or tags
  • tag: Boolean, default: False
    set to True if data list contains tags
  • folder: String, default: empty
    If you want to save the data to a different folder than the one from which you are executing the python file, indicate the respective folder here (use either forward slashes '/' or double backward slashes '\')

Returns: void

Examples

At first: create an instance of the class OpenCity

from opencity import config as conf
from opencity import opencity as oc
cf = conf.Config(PKG_FOLDER=path)
open_city = oc.OpenCity(cf=cf)

Alternatively you can init an OpenCity object without specifying a path - the file holding all current datasets will then be stored in the current working directory:

from opencity import opencity as oc
open_city = oc.OpenCity()

show_data()

show the total number of available data sets and their tags

open_city.show_data()

show an overview

# of all available data sets:
open_city.show_data(overview = True)

# of all indicated data sets:
open_city.show_data(overview = True, data = ["solarpotenzial"]) #you could also indicate several data sets here

# of all available data sets belonging to a certain tag:
open_city.show_data(overview = True, data = ["Geo"], tag = True) #you could also indicate several tags here

show meta data in a popup table

# of all available data sets: 
open_city.show_data(meta = True)

# of all indicated data sets:
open_city.show_data(meta = True, data = ["solarpotenzial"]) #you could also indicate several data sets here

# of all available data sets belonging to a certain tag:
open_city.show_data(meta = True, data = ["Geo"], tag = True) #you could also indicate several tags here

show meta data in the terminal

open_city.show_data(meta = True, terminal = True) #you could also specify data sets or tags

get_data()

get data of a data set

open_city.get_data(["radverkehr_stadtradeln"]) #you could also indicate several data sets here

The output will look something like this:
Loading data
[+] Successfully loaded data set: radverkehr_kampagne_stadtradeln_konstanz_2018_csv
[+] Successfully loaded data set: radverkehr_kampagne_stadtradeln_konstanz_2019_csv
[+] Successfully loaded data set: radverkehr_kampagne_stadtradeln_konstanz_2020_csv

get data of a tag

open_city.get_data(["Soziales"], tag = True) #you could also indicate several tags here

The output will look something like this:
Loading data
[+] Successfully loaded data set: einträge_im_mängelmelder_2017_csv
[-] External Link: Einträge im Mängelmelder 2017 Please visit https://konstanz.hub.arcgis.com/datasets/Konstanz::eintr%C3%A4ge-im-m%C3%A4ngelmelder-seit-dem-01-01-17
[+] Successfully loaded data set: außenwanderung_bei_stadtteil_von_2011_bis_2019_csv
[+] Successfully loaded data set: kindertagesbetreuung_einrichtungen_csv
[+] Successfully loaded data set: kindertagesbetreuung_einrichtungen_json

get meta data of a data set

open_city.get_data(["baumkataster"], meta = True) #you could also indicate several data sets here

The output will look something like this:
Loading data
[+] Successfully loaded meta data of 6 data sets

get meta data of a tag

open_city.get_data(["Politik und Wahlen"], tag = True, meta = True) #you could also indicate several tags here

The output will look something like this:
Loading data
[+] Successfully loaded meta data of 16 data sets

save_data()

save data of a data set

open_city.save_data(["solarpotenzial"]) #you could also indicate several data sets here

The output will look something like this:
Finished saving requested data to C:\Users\username\Desktop\Solarpotenzial 2018.csv
Finished saving requested data to C:\Users\username\Desktop\Solarpotenzial 2018.kml
Finished saving requested data to C:\Users\username\Desktop\Solarpotenzial 2018.zip
Finished saving requested data to C:\Users\username\Desktop\Solarpotenzial 2018.geojson

save data of a tag

open_city.save_data(["Geo"], tag = True) #you could also indicate several tags here

save data to another folder than your project directory

path = "C:/Users/example_path" #important to use either forward slashes or double backward slashes!
opencity.save_data(["standorte_sportanlagen"], folder = path)

Installation

pip install opencity

Potential problems

GeoPandas

When installing the opencity package on a Windows computer, you might run into trouble during the installation due to the package requirement geopandas. This package is necessary for reading in spatial data, which is available for some of the data sets. Please try this page for assistance in installing geopandas.

tk / tkinter

The show_data method has one option to show meta data of available data-sets in a popup window. If you want to use this feature and run into errors (e.g. There is an error with your Tkinter installation, use terminal=True to show the information anyway ) see this AskUbuntu Question or this StackOverflow Question.

However, you can always use the terminal=True parameter to display the same information in the terminal.

Found a bug?

Open an issue including OS, package- and python version, executed code and error message!

Author Information

Birke Pfeifle
Rahkakavee Baskaran
Tilman Kerl
Silke Husse

Email: konstanz@correlaid.org

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

opencity-0.0.1.tar.gz (14.2 kB view hashes)

Uploaded Source

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