An oemof extension to use the oemof related postgis database.
See the documentation for more information!
Use pypi to install the latest oemof version. .. code:: bash pip3 install oemof.db
Unfortunately installing the PyPi package doesn't work until #28 is fixed. Instead, you have to install via:
pip install -e git://github.com/oemof/oemof.db.git@master#egg=oemof.db
Note that you have to have git installed for this to work.
If you want to have the developer version clone the repository by
git clone [email protected]:oemof/oemof.db.git
and you can install it using pip3 with the -e flag.
sudo pip3 install -e <path/to/the/oemof.db/repository/root/directory>
Keep `virtualenvs`_ in mind!
As the purpose of this package is to facilitate usage of the oemof
database, it needs to know how to connect to this database. Being part of
oemof
, as fallback oemof.db
always looks for this configuration in the
file config.ini
in a directory called .oemof
in your home directory.
A particular config-file can either specified and accessed via
from oemof.db import cfg
# only load config file
cfg.load_config(config_file=<you-config-file>)
# access config parameters
cfg.get(<section>, <parameter>)
If you're interested in establishing a database connection and specify config file connection parameters are stored in use
from oemof.db import cfg
# establish database connection with specified section and config_file
db.connection(section=<section>, config_file=<you-config-file>)
To configure database access this file has to have at least one dedicated section containing the necessary options, like this:
[postGIS] username = username under which to connect to the database database = name of the database from which to read host = host to connect to port = port to connect to pw = password used to connect with the given username (OPTIONAL)
The section is assumed to be named postGIS
by default, but you can name it
differently and have multiple sections for different databases if the need
arises.
The password is optional. If you don't want to store the password in the
config.ini
, you may store it using the `keyring package`_, which is a
dependency of oemof.db
, like this:
>>> import keyring >>> keyring.set_password("database", "username")
where "database"
and "username"
have the same values as the
corresponding options in config.ini
.