Skip to main content

Python wrapper for NREL PVWatts's API.

Project description

[![Build Status](https://travis-ci.org/mpaolino/pypvwatts.svg?branch=master)](https://travis-ci.org/mpaolino/pypvwatts)

A NREL PVWAtts API v6 thin Python wrapper built around requests library.

Originally developed by <http://renooble.com>.

Github repository: <https://github.com/mpaolino/pypvwatts>

PVWatts API v6 Documentation: <https://developer.nrel.gov/docs/solar/pvwatts/v6/>

Python requests library: <http://docs.python-requests.org/en/latest/>

Supports

Python 2 & Python 3

Installing

pypvwatts can be installed using distutils/setuptools, either using the setup.py included or directly over PyPi package repository:

Using PyPi

$ pip install pypvwatts

Download the tarball, unpack and then run setup.py

$ python setup.py install

Usage - with class methods

>>> from pypvwatts import PVWatts
>>> PVWatts.api_key = 'myapikey'
>>> result = PVWatts.request(
        system_capacity=4, module_type=1, array_type=1,
        azimuth=190, tilt=30, dataset='tmy2',
        losses=13, lat=40, lon=-105)
>>> result.ac_annual
6683.64501953125

Usage - with instance methods

>>> from pypvwatts import PVWatts
>>> p = PVWatts(api_key='myapikey')
>>> result = p.request(
        system_capacity=4, module_type=1, array_type=1,
        azimuth=190, tilt=30, dataset='tmy2',
        losses=13, lat=40, lon=-105)
>>> result.ac_annual
6683.64501953125

Request parameters and responses

All request parameters correspond to NREL PVWatts API parameters.

This library provides shortcuts for all response output fields, all can be accessed as a result property.

Please refer to NREL PVWatts documentation for further details.

https://developer.nrel.gov/docs/solar/pvwatts/v6/

Raw data

Raw result data can be queried using the result.raw attribute.

>>> from pypvwatts import PVWatts
>>> result = PVWatts.request(
        system_capacity=4, module_type=1, array_type=1,
        azimuth=190, tilt=30, dataset='tmy2',
        losses=13, lat=40, lon=-105)
>>> result.raw
{u'errors': [u'You have exceeded your rate limit. Try again later or contact us at http://developer.nrel.gov/contact for assistance']}

Errors

All API errors are reported via JSON response, using the errors attribute.

>>> from pypvwatts import PVWatts
>>> result = PVWatts.request(
        system_capacity=4, module_type=1, array_type=1,
        azimuth=190, tilt=30, dataset='tmy2',
        losses=13, lat=40, lon=-105)
>>> result.errors
[u'You have exceeded your rate limit. Try again later or contact us at http://developer.nrel.gov/contact for assistance']

All parameters feeded to make the request are validated, all validations follow the restrictions documented in NREL v6 API docs at <https://developer.nrel.gov/docs/solar/pvwatts/v6/>. All validation errors will be raised with pypvwatts.pvwattserror.PVWattsValidationError exception.

pypvwatts does not try to hide the fact is a thin wrapper around requests library so all other service errors such as connectivity or timeouts are raised as requests library exceptions <http://docs.python-requests.org/en/latest/user/quickstart/#errors-and-exceptions>.

Tests

Simple tests are provided in test.py. Run them with:

$ python -m unittest pypvwatts.test

Or the preferred way, testing Python 2.7 and Python 3.9 together using tox (you need to install it):

$ tox

Changelog

3.0.1 - Fix NREL documentation URL in README.

3.0.0 - Updated to PVWatts v6. Minor input validation fixes and generalized tox config to test with any python 3 version.

2.1.0 - Add Python 3 support while maintaining Python 2 backwards compatibility

2.0.3 - Fix pip install under OSX

2.0.2 - Make all requests using HTTPS

2.0.1 - Minor updates to README

2.0.0 - Version is now compatible with PVWatts v5. 2.0.0 is not backwards compatible with 1.2.0. Attributes of the API have changed.

1.2.0 - Fixed proxy handling, now using proxies parameter.

1.1.1 - Updated copyright notice

1.1.0 - Minor import fix and README update

1.0.0 - First release

Author: Miguel Paolino <miguel@renooble.com>, Hannes Hapke <hannes@renooble.com> - Copyright <http://renooble.com>

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

pypvwatts-3.0.1.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file pypvwatts-3.0.1.tar.gz.

File metadata

  • Download URL: pypvwatts-3.0.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.11

File hashes

Hashes for pypvwatts-3.0.1.tar.gz
Algorithm Hash digest
SHA256 e77ea4774e09a7ca81d43313e53f20706edba6e583351efbc2c011a47caaacfa
MD5 425ad1f9353bf811b209b4d28960c549
BLAKE2b-256 c53ea6a8f351bff40f0074610545b14072de58fcd4191e6035524d56db986b5a

See more details on using hashes here.

Supported by

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