Skip to main content

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.

Metadata

Release files for portlandgeneral-api 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for portlandgeneral-api 1.2.0
File Size Uploaded
portlandgeneral_api-1.2.0.tar.gz 35.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for portlandgeneral-api 1.2.0
File Interpreter ABI Platform
portlandgeneral_api-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 88.4 kB

Release files / portlandgeneral_api-1.2.0.tar.gz

Download URL portlandgeneral_api-1.2.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
58e84a3ff4bb9e47e0c60108cd096ae220ba8579f22e462580703c023b2ab8ce
BLAKE2b-256 checksum
How to use checksums
a63b36a42126e63fe4ffc3350b91dddbccec5ccd6d44282f339d5fba4b30c434
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 12, 2025.

Transparency log

Release files / portlandgeneral_api-1.2.0-py3-none-any.whl

Download URL portlandgeneral_api-1.2.0-py3-none-any.whl
Size 52.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba3221d58d7295d714e4d28318492d5def45471637e850d0d1235fceb132c8c0
BLAKE2b-256 checksum
How to use checksums
2668d9b1696397c14f17873682f30f96e79a1b754bcd9785407485ce9f55605e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 12, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page