Skip to content

USEPA/cam-api-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EPA's Clean Air Markets (CAM) API Examples

The purpose of this repo is to provide users examples on how to use the Clean Air Market's (CAM) APIs using Python and R. Users can find documentation of the APIs in the CAM API Portal.

❗ If you are trying to access a lot of data (i.e. a years worth of hourly emissions data) please see the bulk_data_api_demo (R or py)!

Background

About EPA's Clean Air Markets

To learn more about the programs associated with the data through these APIs, as well as other information, visit the Clean Air Markets Division (CAMD) homepage.

Data.gov API key

Visit https://api.data.gov/ to find API documentation for various Federal Government Deparment and Agencies. Be sure to sign up for an API key which can be used not only for the CAM APIs, but also for the other APIs you can find from api.data.gov.

Python Scripts Description

Recommended versions of Python to have installed to use these scripts is 3.8, 3.9 or 3.10.

Before executing the scripts, install the following packages.

pip install requests

pip install pandas

Python/account_data_demo.py

The script retrieves account holdings and allowance compliance data by using the streaming-services and account-mgmt APIs. The script also prints out useful data from the response headers too.

  1. In the file, insert your API key at:

    API_KEY = 'YOUR_API_KEY'

  2. To execute the script run in your terminal:

    cd Python/
    python account_data_demo.py

  3. If successful, you will see a response, `Status code: 200` and the script will continue
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed

Python/emissions_data_demo.py

The script retrieves hourly emissions data by using the streaming-services API and annual emissions data using the emission-mgmt API. The script also prints out useful data from the response headers too.

  1. In the file, insert your API key at:

    API_KEY = 'YOUR_API_KEY'

  2. To execute the script run in your terminal:

    cd Python/
    python emissions_data_demo.py

  3. If successful, you will see a response, `Status code: 200` and the script will continue
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed

Python/facility_data_demo.py

The script retrieves facility attribute data by using the streaming-services and facilities-mgmt APIs. The script also prints out useful data from the response headers too.

  1. In the file, insert your API key at:

    API_KEY = 'YOUR_API_KEY'

  2. To execute the script run in your terminal:

    cd Python/
    python facility_api_demo.py

  3. If successful, you will see a response, `Status code: 200` and the script will continue
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed

Python/bulk_data_api_demo.py

The script retrieves hourly emissions files for virginia using the camd-services API and saves the files in a directory. Additionally, the script will print out other data types and useful things about the bulk files metadata.

  1. In the file, insert your API key at: `API_KEY = 'YOUR_API_KEY'`
  2. To execute the script run in your terminal:

    cd Python/
    python bulk_data_api_demo.py

  3. If successful, you will see a response, `Status code: 200` and the script will continue
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed



R Scripts Description

Recommended versions of R to have installed to use these scripts is R (>= 3.2).

Before executing the scripts, install the following packages.

install.packages("httr")

install.packages("htmltools")

install.packages("jsonlite")

R/account_data_demo.R

The script retrieves account holdings and compliance data by using the streaming-services and account-mgmt APIs. The script also prints out useful data from the response headers too.

  1. In the file, insert your API key at: `apiKEY = 'YOUR_API_KEY'`
  2. To execute the script run in RStudio or in your terminal:

    cd R/
    RScript bulk_data_api_demo.R

  3. If successful, you will see a response, `Status code: 200`
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed

R/emissions_data_demo.R

The script retrieves hourly by using the streaming-services and annual emissionsdata by using the emission-mgmt APIs. The script also prints out useful data from the response headers too.

  1. In the file, insert your API key at: `apiKEY = 'YOUR_API_KEY'`
  2. To execute the script run in RStudio or in your terminal:

    cd R/
    RScript bulk_data_api_demo.R

  3. If successful, you will see a response, `Status code: 200`
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed

R/facility_data_demo.R

The script retrieves facility attribute data by using the streaming-services and facilities-mgmt APIs. The script also prints out useful data from the response headers too.

  1. In the file, insert your API key at: `apiKEY = 'YOUR_API_KEY'`
  2. To execute the script run in RStudio or in your terminal:

    cd R/
    RScript bulk_data_api_demo.R

  3. If successful, you will see a response, `Status code: 200`
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed

R/bulk_data_api_demo.R

The script retrieves hourly emissions files by using the camd-services API and saves the files in a directory. Additionally, the script will print out other data types and useful things about the bulk files metadata.

  1. In the file, insert your API key at: `apiKEY = 'YOUR_API_KEY'`
  2. To execute the script run in RStudio or in your terminal:

    cd R/
    RScript bulk_data_api_demo.R

  3. If successful, you will see a response, `Status code: 200`.
  4. If not succesful, the script has a catch and prints out an error message as to why the API call failed


Disclaimer

The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity , confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government.