pandahub


Namepandahub JSON
Version 0.5.2 PyPI version JSON
download
home_pageNone
SummaryData hub for pandapower and pandapipes networks based on MongoDB
upload_time2025-07-28 08:26:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseCopyright (c) 2022 by University of Kassel, Fraunhofer Institute for Energy Economics and Energy System Technology (IEE) Kassel, retoflow GmbH individual contributors (see AUTHORS file for details). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords analysis automation energy engineering grid network optimization simulation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![pandapower](https://www.pandapower.org/images/pp.svg)](https://www.pandapower.org)         [![pandapipes](https://www.pandapipes.org/images/pp.svg)](https://www.pandapipes.org)

[![pandahub](https://img.shields.io/pypi/v/pandahub?label=pypi%20package&color=green)](https://pypi.org/project/pandahub/) [![pandahub](https://img.shields.io/pypi/pyversions/pandahub.svg)](https://pypi.org/project/pandahub/) [![pandahub](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/e2nIEE/pandahub/blob/master/LICENSE)

pandahub is a data hub for pandapower and pandapipes networks based on MongoDB. It allows you to store pandapower and
pandapipes networks as well as timeseries in a MongoDB. pandahub allows you to access the database directly through the
PandaHub class, but also provides a REST-API based on FastAPI including authentication (implemented with FastAPI Users).

## PandaHub example
Run `uv sync` and bring up a local mongodb instance with `docker compose up db -d`.

Save pandapower's `mv_oberrhein` network to the database:
```pycon
>>> net = pp.networks.mv_oberrhein()
>>> ph = PandaHub()
>>> project_data = ph.create_project("MV Oberrhein Example")
>>> net_data = ph.write_network_to_db(net, name="mv_oberrhein", net_id=0)
```
Close a switch in the database:
```pycon
>>> open_switch_idx = net.switch.query("closed==False").index.to_list()[0]
>>> ph.set_net_value_in_db(net_id=0, element_type="switch", element_index=open_switch_idx,
                           parameter="closed", value=True)

```
Retrieve the network from the database and confirm the switch is now closed:
```pycon
>>> net_from_db = ph.get_network(net_id=0)
>>> net.switch.loc[open_switch_idx, "closed"]
np.False_
>>> net_from_db.switch.loc[open_switch_idx, "closed"]
np.True_
```

## REST-api
Run `uv sync --extra rest-api` to set up your venv with the required dependencies, then build the docker image and bring up a
mongodb database + the rest-api:

```console
docker compose build
docker compose up -d
```
This will run the example app in `pandahub/api/main.py` with live reload at http://localhost:8002.
To connect to an existing database instead, set `MONGODB_URL` to the connection string through an environment variable or in you `.env` file.

Swagger UI is available at http://localhost:8002/docs.

## MongoClient handling

You can supply a mongodb connection string (or the host as connection string and user/password separately) either as arguments to PandaHub
or by setting the following environment variables:

* MONGODB_URL
* MONGODB_USER (optional)
* MONGODB_PASSWORD (optional)

These values are then used as default arguments when creating a PandaHub object.

By default, each instantiation of a PandaHub instance will create a new MongoClient instance. This is fine for interactive use or small scripts. To clean up the mongo client, call `ph.close()` on the instance once you are done with it.

When running the pandahub API as a web application, provide database credentials through the environment variables and additionally set `PANDAHUB_GLOBAL_DB_CLIENT` to `true`.
A single, global mongodb client instance per process will then be used for all PandaHub instantiations, as recommended by [pymongo](https://pymongo.readthedocs.io/en/stable/faq.html#how-does-connection-pooling-work-in-pymongo).

You can use the following properties to access database resources from a PandaHub object:

* *ph.project_db*: database of the activated project (e.g. `ph.project_db.net_bus.find().to_list()`)
* *ph.mgmt_db*: the user_management database
* *ph.users_collection*: the users collection from the management database
* *ph.projects_collection*: the projects collection from the management database


In case you want to access the database but do not need a PandaHub object, there are two convenience functions available:

```python
from pandahub.lib import get_mongo_client

my_collection = get_mongo_client("db", "collection")
docs = collection.find().to_list()
```
`PANDAHUB_GLOBAL_DB_CLIENT` is respected, you either get the global client or a fresh instance, in which case you are responsible for cleaning up the connection.

```python
from pandahub.lib import mongo_client

with mongo_client("db", "my_collection") as collection:
    docs = collection.find().to_list()
```
With the context manager, a new MongoClient is created (even if `PANDAHUB_GLOBAL_DB_CLIENT` is `true`) and closed on completion of the with block.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pandahub",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "analysis, automation, energy, engineering, grid, network, optimization, simulation",
    "author": null,
    "author_email": "Jan Ulffers <jan.ulffers@iee.fraunhofer.de>, Leon Thurner <leon.thurner@retoflow.de>, Jannis Kupka <jannis.kupka@retoflow.de>, Mike Vogt <mike.vogt@iee.fraunhofer.de>, Joschka Thurner <joschka.thurner@retoflow.de>, Alexander Scheidler <alexander.scheidler@iee.fraunhofer.de>",
    "download_url": "https://files.pythonhosted.org/packages/21/bb/33fd845a5343a030f42426e5949f1325061e26406d1f69ff097b388cfd7b/pandahub-0.5.2.tar.gz",
    "platform": null,
    "description": "[![pandapower](https://www.pandapower.org/images/pp.svg)](https://www.pandapower.org)         [![pandapipes](https://www.pandapipes.org/images/pp.svg)](https://www.pandapipes.org)\n\n[![pandahub](https://img.shields.io/pypi/v/pandahub?label=pypi%20package&color=green)](https://pypi.org/project/pandahub/) [![pandahub](https://img.shields.io/pypi/pyversions/pandahub.svg)](https://pypi.org/project/pandahub/) [![pandahub](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/e2nIEE/pandahub/blob/master/LICENSE)\n\npandahub is a data hub for pandapower and pandapipes networks based on MongoDB. It allows you to store pandapower and\npandapipes networks as well as timeseries in a MongoDB. pandahub allows you to access the database directly through the\nPandaHub class, but also provides a REST-API based on FastAPI including authentication (implemented with FastAPI Users).\n\n## PandaHub example\nRun `uv sync` and bring up a local mongodb instance with `docker compose up db -d`.\n\nSave pandapower's `mv_oberrhein` network to the database:\n```pycon\n>>> net = pp.networks.mv_oberrhein()\n>>> ph = PandaHub()\n>>> project_data = ph.create_project(\"MV Oberrhein Example\")\n>>> net_data = ph.write_network_to_db(net, name=\"mv_oberrhein\", net_id=0)\n```\nClose a switch in the database:\n```pycon\n>>> open_switch_idx = net.switch.query(\"closed==False\").index.to_list()[0]\n>>> ph.set_net_value_in_db(net_id=0, element_type=\"switch\", element_index=open_switch_idx,\n                           parameter=\"closed\", value=True)\n\n```\nRetrieve the network from the database and confirm the switch is now closed:\n```pycon\n>>> net_from_db = ph.get_network(net_id=0)\n>>> net.switch.loc[open_switch_idx, \"closed\"]\nnp.False_\n>>> net_from_db.switch.loc[open_switch_idx, \"closed\"]\nnp.True_\n```\n\n## REST-api\nRun `uv sync --extra rest-api` to set up your venv with the required dependencies, then build the docker image and bring up a\nmongodb database + the rest-api:\n\n```console\ndocker compose build\ndocker compose up -d\n```\nThis will run the example app in `pandahub/api/main.py` with live reload at http://localhost:8002.\nTo connect to an existing database instead, set `MONGODB_URL` to the connection string through an environment variable or in you `.env` file.\n\nSwagger UI is available at http://localhost:8002/docs.\n\n## MongoClient handling\n\nYou can supply a mongodb connection string (or the host as connection string and user/password separately) either as arguments to PandaHub\nor by setting the following environment variables:\n\n* MONGODB_URL\n* MONGODB_USER (optional)\n* MONGODB_PASSWORD (optional)\n\nThese values are then used as default arguments when creating a PandaHub object.\n\nBy default, each instantiation of a PandaHub instance will create a new MongoClient instance. This is fine for interactive use or small scripts. To clean up the mongo client, call `ph.close()` on the instance once you are done with it.\n\nWhen running the pandahub API as a web application, provide database credentials through the environment variables and additionally set `PANDAHUB_GLOBAL_DB_CLIENT` to `true`.\nA single, global mongodb client instance per process will then be used for all PandaHub instantiations, as recommended by [pymongo](https://pymongo.readthedocs.io/en/stable/faq.html#how-does-connection-pooling-work-in-pymongo).\n\nYou can use the following properties to access database resources from a PandaHub object:\n\n* *ph.project_db*: database of the activated project (e.g. `ph.project_db.net_bus.find().to_list()`)\n* *ph.mgmt_db*: the user_management database\n* *ph.users_collection*: the users collection from the management database\n* *ph.projects_collection*: the projects collection from the management database\n\n\nIn case you want to access the database but do not need a PandaHub object, there are two convenience functions available:\n\n```python\nfrom pandahub.lib import get_mongo_client\n\nmy_collection = get_mongo_client(\"db\", \"collection\")\ndocs = collection.find().to_list()\n```\n`PANDAHUB_GLOBAL_DB_CLIENT` is respected, you either get the global client or a fresh instance, in which case you are responsible for cleaning up the connection.\n\n```python\nfrom pandahub.lib import mongo_client\n\nwith mongo_client(\"db\", \"my_collection\") as collection:\n    docs = collection.find().to_list()\n```\nWith the context manager, a new MongoClient is created (even if `PANDAHUB_GLOBAL_DB_CLIENT` is `true`) and closed on completion of the with block.\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2022 by University of Kassel, Fraunhofer Institute for Energy Economics and Energy System Technology (IEE) Kassel, retoflow GmbH individual contributors (see AUTHORS file for details). All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted  provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  3. Neither the name of the copyright holder nor the names of its contributors may be used to  endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "Data hub for pandapower and pandapipes networks based on MongoDB",
    "version": "0.5.2",
    "project_urls": {
        "Changelog": "https://github.com/e2nIEE/pandahub/blob/develop/CHANGELOG.md",
        "Documentation": "https://pandapipes.readthedocs.io",
        "Download": "https://pypi.org/project/pandahub/#files",
        "Homepage": "https://github.com/e2nIEE/pandahub",
        "Issues": "https://github.com/e2nIEE/pandahub/issues",
        "Repository": "https://github.com/e2nIEE/pandahub.git",
        "Source": "https://github.com/e2nIEE/pandahub"
    },
    "split_keywords": [
        "analysis",
        " automation",
        " energy",
        " engineering",
        " grid",
        " network",
        " optimization",
        " simulation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "484a0b835071f72feda150688cf80da276bd897c2648a0d82f96e0313a4d586b",
                "md5": "044b7f586312da2851505134bc2149a0",
                "sha256": "0ea5fa57ffa718d0ae2db2d24673fec8e0cb4360be5cee86bd312d2074d3af0f"
            },
            "downloads": -1,
            "filename": "pandahub-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "044b7f586312da2851505134bc2149a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 47637,
            "upload_time": "2025-07-28T08:26:21",
            "upload_time_iso_8601": "2025-07-28T08:26:21.020999Z",
            "url": "https://files.pythonhosted.org/packages/48/4a/0b835071f72feda150688cf80da276bd897c2648a0d82f96e0313a4d586b/pandahub-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "21bb33fd845a5343a030f42426e5949f1325061e26406d1f69ff097b388cfd7b",
                "md5": "379f75d1cbb1d505989b7174d5954a9b",
                "sha256": "7a5a7e33192649756dbc85c8bc27b36b5af65419b8cd8db9baad89d4ec37a480"
            },
            "downloads": -1,
            "filename": "pandahub-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "379f75d1cbb1d505989b7174d5954a9b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 272935,
            "upload_time": "2025-07-28T08:26:21",
            "upload_time_iso_8601": "2025-07-28T08:26:21.994990Z",
            "url": "https://files.pythonhosted.org/packages/21/bb/33fd845a5343a030f42426e5949f1325061e26406d1f69ff097b388cfd7b/pandahub-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-28 08:26:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "e2nIEE",
    "github_project": "pandahub",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pandahub"
}
        
Elapsed time: 0.58035s