Skip to main content

Data hub for pandapower and pandapipes networks based on MongoDB

Project description

from lib import get_mongo_clientpandapower pandapipes

pandahub pandahub pandahub

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. Access through the API is managed with a user management implementation based on FastAPI Users.

Development

docker compose up -d runs a mongodb container alongside a pandahub api instance with live reload available at http://localhost:8002. To connect to an existing database instead, set MONGODB_URL to the connection string through an environment variable / in you .env file.

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

If you develop on the library and do not need the fastapi app, docker compose up db -d starts only the mongodb container.

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.

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:

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.

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.

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

pandahub-0.3.17.zip (67.2 kB view details)

Uploaded Source

File details

Details for the file pandahub-0.3.17.zip.

File metadata

  • Download URL: pandahub-0.3.17.zip
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for pandahub-0.3.17.zip
Algorithm Hash digest
SHA256 c6ab26451dcfcceb80edec822de86fef9f25383c40fc55e2f56a0790fdb9b38e
MD5 cb030c82e3e8ea9d8cb2fcad24cbb498
BLAKE2b-256 fc07da25d4eec8529078d98dee47d826d6b9dc934b5ae52e471e7dd23885b0b7

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