{ "cells": [ { "cell_type": "markdown", "id": "7c549d6c-3abe-487b-89c8-ef1dce7911d8", "metadata": {}, "source": [ "# API Rate Limits\n", "\n", "The NSRDB API [docs](https://developer.nrel.gov/docs/rate-limits/) mention that total and remaining request/rate limit information is included in the HTTP headers of the API response. This is not currently returned by pvlib's `get_psm3()` (maybe it should be?), so here's a quick way of accessing it yourself." ] }, { "cell_type": "code", "execution_count": 1, "id": "4044b936-fa83-474b-99d5-073fdc8bb758", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10 remaining of 40\n" ] } ], "source": [ "import requests\n", "api_key = 'DEMO_KEY'\n", "response = requests.head('https://developer.nrel.gov/api/nsrdb/v2/solar/psm3-tmy-download.csv?api_key=' + api_key)\n", "print(response.headers['X-Ratelimit-Remaining'], 'remaining of', response.headers['X-Ratelimit-Limit'])" ] }, { "cell_type": "code", "execution_count": 2, "id": "7d02c579-4022-4766-90ce-d93c77d483ca", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last updated: 2022-09-22 21:45:59\n", "\n", "requests: 2.28.1\n", "\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark --iversions -u -d -t" ] }, { "cell_type": "code", "execution_count": null, "id": "3bd7f6bb-e3b5-4aa1-be2f-0feb574bf5c2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 5 }