Skip to main content

Unofficial Python library for communicating with the Portland General (Electric) API

Project description

portlandgeneral-api

An unofficial Python library for requesting data from the Portland General Electric (PGE) API.

Portland General (PGE): https://portlandgeneral.com/

API: https://api.portlandgeneral.com/

PGE GraphQL Endpoint: https://api.portlandgeneral.com/pge-graphql

Installation

The package is availble via PyPi and can be installed with the following command:

pip3 install portlandgeneral-api

To install it from the repo, clone the repo and cd into the directory:

git clone https://github.com/piekstra/portlandgeneral-api.git
cd portlandgeneral-api

You can install this library with pip:

pip3 install .

Examples

There are two examples available, one for the PortlandGeneralApi and one for the OPowerApi.

Testing

This project leverages wiremock to test the code to some extent. Note this will not protect the project from changes that Portland General makes to their API, but instead verifies that the existing code functions consistently as written.

Local Testing

Note that the tests setup leverages the local_env_vars.py file. The values for those environment variables need to be set based on the following:

  • PORTLANDGENERAL_USERNAME: example@email.com - This must have parity with the email in the body specified in tests/wiremock/mappings/jwt_request.json
  • PORTLANDGENERAL_PASSWORD: portlandgeneral_password - This must have parity with the password in the body specified in tests/wiremock/mappings/jwt_request.json
  • IDP_HOST_OVERRIDE: http://127.0.0.1:9090 - This URL is simply http://127.0.0.1 but the url port must have parity with the docker-compose.yaml wiremock service's exposed http port.
  • API_HOST_OVERRIDE: http://127.0.0.1:9090 - This URL is simply http://127.0.0.1 but the url port must have parity with the docker-compose.yaml wiremock service's exposed http port.

To run tests, you will first need to start the wiremock service by running:

docker-compose up -d

Then, you can run the actual tests with the following command:

pytest --verbose

GitHub Testing

This project leverages GitHub Actions and has a workflow that will run these tests. The environment configuration for the tests must have parity with the local_env_vars.py file from the local testing.

Releases

Releases should follow a Semantic Versioning scheme.

When changes have been made that warrant a new release that should be published, modify the __version__ in setup.py

After the change is merged to the main branch, go to releases and Draft a new release. The Tag version should follow the pattern v1.0.0 and should Target the main branch.

The Release title should not include the v from the tag and should have a reasonably detailed description of the new release's changes.

Once the release has been published, the .github/workflows/python-publish.yml GitHub Actions Workflow should trigger and automatically upload the new version to PyPi using GitHub secrets credentials.

Not-so-secret Keys

Certain values found in constants.py are copied from the Portland General's Website where they conveniently left their source maps. Those values are in fact not tied to a personal account with Portland General, but are instead specific to their deployments.

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

portlandgeneral-api-1.1.0.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

portlandgeneral_api-1.1.0-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

Details for the file portlandgeneral-api-1.1.0.tar.gz.

File metadata

  • Download URL: portlandgeneral-api-1.1.0.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for portlandgeneral-api-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ded84cfa1f769a67609e6719124ff27e91c1bd5e8ab988c79783d829f92004bf
MD5 57d954540f27ab31e7c6b93db3c65e67
BLAKE2b-256 cc0c1ab7115d2ac4b5aac5103d8e9c3b038d5507e7f6db81e6fdf1f32a8dd8c6

See more details on using hashes here.

File details

Details for the file portlandgeneral_api-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for portlandgeneral_api-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 509fcced0d2b92d0cc55a9f9935cbab4891ec5a8784b60d028e26d3bddfe8090
MD5 d88284fca7e9d13635a4892e647c6064
BLAKE2b-256 b3cec139cde4888bb2317fae96d80bd98d305cb6e62cb227c20fd8614d5a9140

See more details on using hashes here.

Supported by

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