Skip to content

refinerycalc/sdk-example-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Refinery Calc SDK Examples

This repository contains some examples on how to use the Refinery Calc Python SDK client which wraps the Refinery Calc API.

Getting Started

  • Clone the repository
  • cd into the root directory
  • create a python virtual environment
python -m venv .venv

Activate the virtual environment (macOS)

source .venv/bin/activate

Activate the virtual environment (Windows)

.venv\Scripts\activate

Install the Refinery Calc SDK

pip install refinerycalc-api

Runing the Sample Code

Api Key

Ensure you add your API Key to an Environment Variable RefineryCalc_Api_Key

Windows Cmd
set RefineryCalc_Api_Key=<YOUR API KEY HERE>

macOS

export RefineryCalc_Api_Key=<YOUR API KEY HERE>

Run Sample Code

Create a simulation

python create_simulation.py

Run the simulation

use the simulation id from the previous step. Modify the run_simulation.py file to include the simulation id and then run the following

python run_simulation.py

To Use in Your Own Program

Add the following code setup where you need it

class RefineryCalcExampleClient:
    def __init__(self):
        # Get API key and URL from environment variables
        api_key = os.getenv("RefineryCalc_Api_Key")
        api_url = os.getenv("RefineryCalc_Api_Url", "https://api.refinerycalc.com")  # Default URL if not set
        
        # Error handling for missing API key
        if api_key is None:
            raise ValueError("API key is not set. Please set RefineryCalc_Api_Key in your environment.")
        
        # Set up configuration
        config = Configuration()
        config.api_key = api_key
        config.host = api_url
        
        # Initialize the API client
        self.__apiClient = ApiClient(configuration=config, header_name="x-api-key", header_value=config.api_key)
        
        # Set up APIs
        self.simulations = SimulationsApi(self.__apiClient)
        self.refineries = RefineriesApi(self.__apiClient)
        self.productPrices = ProductPricesApi(self.__apiClient)

Create Simulation

to create a new simulation, you will need the list of refineries that will be used in that simulation. See the sample code below:

    refs = [7, 8, 9, 10]
client = RefineryCalcExampleClient()
req = CreateSimulationRequest()
req.refineries = refs
# 0 is default datasource and 1 for IIR
req.data_source = 0
req.name = "my new simulation"
req.is_time_series = False
response = client.simulations.v1_simulations_post(body=req)
if response.success:
    print(response.simulation_id)

About

example on how to access the Refinery Calc API using the SDK Client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •