Skip to main content

An unofficial Python module for interacting with Srp Energy data.

Project description

https://travis-ci.org/lamoreauxlab/srpenergy-api-client-python.svg?branch=master https://coveralls.io/repos/github/lamoreauxlab/srpenergy-api-client-python/badge.svg?branch=master Documentation Status Requirements Status Latest version on PyPi Supported Python versions

The srpenergy module is an unofficial Python module for interacting with Srp Energy data.

Srp provides an hourly energy usage report for their customers. The srpenergy module fetches the data found via the api.

The data returned from the hourly url https://myaccount.srpnet.com/myaccountapi/api/usage/hourlydetail?billaccount=<code>&beginDate=<MM-DD-YYYY>&endDate=<MM-DD-YYYY>

{   "hourlyConsumptionList": [],
    "hourlyGenerationList": [],
    "hourlyReceivedList": [],
    "hourlyUsageList":[{
            "date": "2019-10-09T00:00:00",
            "hour": "2019-10-09T00:00:00",
            "onPeakKwh": 0.0,
            "offPeakKwh": 0.0,
            "shoulderKwh": 0.0,
            "superOffPeakKwh": 0.0,
            "totalKwh": 0.4,
            "onPeakCost": 0.0,
            "offPeakCost": 0.0,
            "shoulderCost": 0.0,
            "superOffPeakCost": 0.0,
            "totalCost": 0.08
        }
    ],
    "demandList":[]
}

Installing

It is distributed on PyPI and can be installed with pip:

pip install srpenergy

Use

from datetime import datetime, timedelta
from srpenergy.client import SrpEnergyClient

accountid = 'your account id'
username = 'your username'
password = 'your password'
end_date = datetime.now()
start_date = datetime.now() - timedelta(days=2)

client = SrpEnergyClient(accountid, username, password)
usage = client.usage(start_date, end_date)

date, hour, isodate, kwh, cost = usage[0]

For Time of use plans pass in the argument is_tou

from datetime import datetime, timedelta
from srpenergy.client import SrpEnergyClient

accountid = 'your account id'
username = 'your username'
password = 'your password'
end_date = datetime.now()
start_date = datetime.now() - timedelta(days=2)

client = SrpEnergyClient(accountid, username, password)
usage = client.usage(start_date, end_date, True)

date, hour, isodate, kwh, cost = usage[0]

Development

Style Guidelines

This project enforces quite strict PEP8 and PEP257 (Docstring Conventions) compliance on all code submitted.

We use Black for uncompromised code formatting.

Summary of the most relevant points:

  • Comments should be full sentences and end with a period.

  • Imports should be ordered.

  • Constants and the content of lists and dictionaries should be in alphabetical order.

  • It is advisable to adjust IDE or editor settings to match those requirements.

Ordering of imports

Instead of order the imports manually, use isort.

pip3 install isort
isort .

Use new style string formatting

Prefer f-strings over % or str.format.

#New
f"{some_value} {some_other_value}"
# Old, wrong
"{} {}".format("New", "style")
"%s %s" % ("Old", "style")

One exception is for logging which uses the percentage formatting. This is to avoid formatting the log message when it is suppressed.

_LOGGER.info("Can't connect to the webservice %s at %s", string1, string2)

Testing

As it states in the Style Guidelines section all code is checked to verify the following:

  • All the unit tests pass

  • All code passes the checks from the linting tools

Local testing is done using Tox. To start the tests, activate the virtual environment and simply run the command:

tox

Testing outside of Tox

Running tox will invoke the full test suite. To be able to run the specific test suites without tox, you’ll need to install the test dependencies into your Python environment:

pip3 install -r requirements_test.txt

Now that you have all test dependencies installed, you can run tests on the project:

isort .
codespell  --skip="./.*,*.csv,*.json,*.pyc,./docs/_build/*,./htmlcov/*"
black setup.py srpenergy tests
flake8 setup.py srpenergy tests
pylint setup.py srpenergy tests
pydocstyle setup.py srpenergy tests
python -m pytest tests
python -m pytest --cov-report term-missing --cov=srpenergy

Building Docs

Build the documentation locally with

cd docs
python -m sphinx -T -b html -d _build/doctrees -D language=en . _build/html

Package and Deploy

After a successful build, packageing and deploying will:

  • Bump Version

  • Tag version in git

  • Create Release in git

  • Release to pypi

Bump Version

Change the version in the following files:

  • srpenergy/__init__.py

  • docs/conf.py

Tag Version

Commit, tag, and push the new version

git commit -m "Bump version"
git tag -a 1.3.1 -m "1.3.1"
git push --tags

Create Release

Name the Release the same as the tag name

Release to pypi

Upgrade to the latest version of setuptools and create package and test

python -m pip install --user --upgrade setuptools wheel # Get latest version
python setup.py sdist bdist_wheel
twine check dist/*

Upload the package to test first

python -m twine upload --repository testpypi dist/*

Check that package looks ok. After testing, upload to the main repository

python -m twine upload dist/*

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

srpenergy-1.3.5.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

srpenergy-1.3.5-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

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