class pydriosm.ios.PostgresOSM(host=None, port=None, username=None, password=None, database_name=None, data_source='Geofabrik', max_tmpfile_size=None, data_dir=None, **kwargs)[source]

Implement storage I/O of OSM data with PostgreSQL.

  • host (str | None) – host name/address of a PostgreSQL server, e.g. 'localhost' or '' (default by installation of PostgreSQL); when host=None (default), it is initialized as 'localhost'

  • port (int | None) – listening port used by PostgreSQL; when port=None (default), it is initialized as 5432 (default by installation of PostgreSQL)

  • username (str | None) – username of a PostgreSQL server; when username=None (default), it is initialized as 'postgres' (default by installation of PostgreSQL)

  • password (str | int | None) – user password; when password=None (default), it is required to mannually type in the correct password to connect the PostgreSQL server

  • database_name (str | None) – name of a database; when database=None (default), it is initialized as 'postgres' (default by installation of PostgreSQL)

  • confirm_db_creation – whether to prompt a confirmation before creating a new database (if the specified database does not exist), defaults to False

  • data_source (str) – name of data source, defaults to 'Geofabrik'; options include {'Geofabrik', 'BBBike'}

  • max_tmpfile_size (int | None) – defaults to None, see also the function pyhelpers.settings.gdal_configurations()

  • data_dir (str | None) – directory where the data file is located/saved, defaults to None; when data_dir=None, it should be the same as the directory specified by the corresponding downloader/reader

  • kwargs – [optional] parameters of the class pyhelpers.sql.PostgreSQL


data_source (str) – name of data sources, options include {'Geofabrik', 'BBBike'}


>>> from pydriosm.ios import PostgresOSM

>>> osmdb = PostgresOSM(database_name='osmdb_test')
Password (postgres@localhost:5432): ***
Creating a database: "osmdb_test" ... Done.
Connecting postgres:***@localhost:5432/osmdb_test ... Successfully.

>>> osmdb.data_source
>>> type(osmdb.downloader)
>>> type(osmdb.reader)

>>> # Change the data source
>>> osmdb.data_source = 'BBBike'
>>> type(osmdb.downloader)
>>> type(osmdb.reader)

>>> # Delete the database 'osmdb_test'
>>> osmdb.drop_database(verbose=True)
To drop the database "osmdb_test" from postgres:***@localhost:5432
? [No]|Yes: yes
Dropping "osmdb_test" ... Done.



list: Names of the data sources.


dict: Specify a data-type dictionary for data or columns in PostgreSQL database and Pandas.


Instance of either the class GeofabrikDownloader or BBBikeDownloader, depending on the specified data_source for creating an instance of the class PostgresOSM.


Name of the current property downloader.


Instance of either GeofabrikReader or BBBikeReader, depending on the specified data_source for creating an instance of the calss PostgresOSM.


Homepage URL of data resource for current property downloader.


decode_pbf_layer(layer_dat[, decode_geojson])

Process raw data of a PBF layer retrieved from database.

drop_subregion_tables(subregion_names[, ...])

Delete all or specific schemas/layers of subregion data from the database being connected.

fetch_osm_data(subregion_name[, ...])

Fetch OSM data (of one or multiple layers) of a geographic (sub)region.

get_table_column_info(subregion_name, layer_name)

Get information about columns of a specific schema and table data of a geographic (sub)region.

get_table_name(subregion_name[, ...])

Get the default table name for a specific geographic (sub)region.

import_osm_data(osm_data, table_name[, ...])

Import OSM data into a database.

import_osm_layer(layer_data, table_name, ...)

Import one layer of OSM data into a table.

import_subregion_osm_pbf(subregion_names[, ...])

Import data of geographic (sub)region(s) that do not have (sub-)subregions into a database.

subregion_table_exists(subregion_name, ...)

Check if a table (for a geographic (sub)region) exists.