Skip to main content

SQLAlchemy module to generate ORM, read from data model in open-energy-metadata(oem-v1.4.0) JSON format

Project description

OEM to ORM

Create database tables (and schema) from oemetadata json file(s)

Installation:

This Package is currently in Alpha. We use the Test PyPi instance until all Unit-test and UX-test passed. To install Packages listed there we recommend using the following command with Pip:

pip install -i https://test.pypi.org/simple/ oem2orm

Usage:

This tool is part of the open-energy-metadata (OEM) integration into the OEP. To use this tool with the OEP API you need to be signed up to the OEP since you need to provide an API-Token.

If you want to upload OEM that was officially reviewed you must clone the OEP data-preprocessing repository on GitHub. The data-review folder contains all of the successfully reviewed OEM files.

For security reasons, tables can only be created in existing schemas and just in the schemas "model_draft" and "sandbox".

Keep in mind the current state is not fully tested. The code is still quit error prone f.e. the postgres types (column datatype) are not fully supported by the oedialct - work in progress.

CLI-Application

Step-by-Step:

  1. Create env from requirements.txt, and activate
  2. Put the metadata file in the folder metadata or put your own folder in this directory
  3. execute the following in a cmd:
python oep_oedialect_oem2orm.py
  1. Provide credentials and folder name in prompt
  2. The table will be created

Import as Module

You can simply import this module in your Python script.py like this:

from oem2orm import oep_oedialect_oem2orm as oem2orm

Now just call the functions provided in oem2orm like this:

Recommended execution order:

  • Setup the logger
oem2orm.setup_logger()
  • Setup the Database API connection as Namedtuple storing the SQLAlchemy engine and metadata:
db = oem2orm.setup_db_connection()
  • Provide the oem files in a folder (in the current directory).
  • Pass the folder name to the function:
metadata_folder = oem2orm.select_oem_dir(oem_folder_name="folder_name")
  • Setup a SQLAlchemy ORM including all data-model in the provided oem files:
orm = oem2orm.collect_ordered_tables_from_oem(db, metadata_folder)
  • Create the tables on the Database:
oem2orm.create_tables(db, orm)
  • Delete all tables that have been created (all tables available in sa.metadata)
oem2orm.delete_tables(db, orm)

Docs:

Database connection

We use a global namedtuple called "DB" To store the sqlalchemy connection objects engine and metadata. The namedtuple is available wen import oem2orm in a script. To establish the namedtuple use the function setup_db_connection(). Now you can use DB.engine or DB.metadata.

oem2orm generator

Supported datatypes

Spatial Types

We create columns with spatial datatypes using Geoalchemy2.

Database support

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

oem2orm-0.2.5.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oem2orm-0.2.5-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file oem2orm-0.2.5.tar.gz.

File metadata

  • Download URL: oem2orm-0.2.5.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for oem2orm-0.2.5.tar.gz
Algorithm Hash digest
SHA256 57ae6df22b5c0a26bb71752287205e46b4fd4ae886f7e8cacbfe0423329f0d79
MD5 f07ec2afc2f2b67fe8f01d735c11a8c3
BLAKE2b-256 1282d2eb1b8e96f6c722d944b4c3eeb1a06fc1fce6cf0baca1b3e946f8bef98d

See more details on using hashes here.

File details

Details for the file oem2orm-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: oem2orm-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for oem2orm-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3c5f8e978d42cdf3a3d85c01f02327d5b4d4eb7b19ce5f054f095bf3d9f896b2
MD5 1a14b760efb99394cf72a9a5c7ae1869
BLAKE2b-256 09cc1079b989f02d369929ec764a4ef792d917318b4c65cd3d0e3254398d725b

See more details on using hashes here.

Supported by

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