Getting Started
The main interface for the Tyba Python Client is the Client class:
import os
from tyba_client.client import Client
PAT = os.environ["TYBA_PAT"]
client = Client(PAT)
As you can see in the above example, you must have a Tyba PAT (Personal Access Token) in order to use the Client. The Authentication section below explains how to store your PAT in your local environment. With the PAT stored and a client instance instantiated, we can easily simulate projects and pull energy price data.
Run a Simulation
- Make the necessary imports: - from generation_models import PVGenerationModel, PVSystemDesign, SingleAxisTracking 
- Define a simple model: - model = PVGenerationModel( solar_resource=(40.6685396, -73.9345585), inverter="Delta Electronics: M80U_XXX [480V]", pv_module="Boviet Solar Technology Co._ Ltd. BVM6612M-315", system_design=PVSystemDesign( dc_capacity=2000.0, ac_capacity=1500.0, poi_limit=15000.0, gcr=0.38, tracking=SingleAxisTracking( rotation_limit=45.0, backtrack=True ) ), project_term=1 ) 
- Schedule the model run and get the run id: - res = client.schedule(model) id_ = res.json()["id"] print(res.text) - You will see an id print, confirming that the run has been scheduled. 
- Wait to receive the results: - results = client.wait_on_result(id_) 
- View and explore the results - # Results is a dictionary. To review keys: print(results.keys()) # Review System Power 8760 results['system_power'] 
Pull Historical Price Data
- Get a list of all the independent system operators (ISOs) represented in the dataset - print(client.services.get_all_isos().json()) 
- Get a list of all of the Local Market Price (LMP) nodes for a given ISO - price_nodes = client.lmp.get_all_nodes(iso='CAISO').json() node_directory = pd.DataFrame(price_nodes) print(node_directory.head()) 
- Get a pandas Series of LMP prices based on node id - res = client.lmp.get_prices( node_ids=['20000004677'], market=Market.RT, start_year=2024, end_year=2024 ).json() res = res['20000004677'] df = pd.Series(res['prices'], index=pd.to_datetime(res['datetimes'])).tz_localize(None) print(node_directory.head()) 
Pull a Price Forecast
- Define a time range of interest - tz = pytz.timezone("US/Central") # Can be any timezone but results will always be returned in the node-local timezone start_time = tz.localize(datetime(2023, 10, 10)) # localized datetime is required to avoid ambiguity end_time = tz.localize(datetime(2023, 10, 17)) # localized datetime is required to avoid ambiguity 
- Pull the most recent forecast for an LMP node based on node name - node_name = "HB_HOUSTON" # Use client.lmp.get_all_nodes from the previous section to find your node name da_forecasts = forecast.most_recent(node_name, "da", start_time, end_time) # Results are a list of dicts. To see the first dict: print(da_forecasts[0]) 
Next…
Feel free to dig deeper with the the Project Simulation Service, Historical Price Service, and Price Forecast Service pages, which discuss the usage of their respective features in greater detail
Authentication
As mentioned above, you must have a Tyba PAT to use the Client. If you do not have or know your PAT, please contact us.
Mac or Linux instructions
Shell Environment (preferred)
Save your Tyba PAT in the shell’s environment:
- Add - TYBA_PAT="your-pat-in-quotes"to a new line in ~/.bashrc
- To check, open a new shell/terminal and run - envand confirm- TYBA_PATis present and properly set
This approach is preferred even if you are running a Jupyter notebook because it keeps the PAT from being exposed if the notebook/script is shared
Jupyter Notebook
Save your Tyba PAT in the notebook’s environment:
- In a notebook cell, enter the following:
- %env TYBA_PAT=your_pat_without_quotes 
 
- The cell will return your key with “env: TYBA_PAT = your_pat_without_quotes” 
- To keep the PAT secure, delete the previous cell. You will need to repeat this process each time you open the notebook 
Windows Instructions
Shell Environment
On a Windows machine, the simplest (but less secure) approach is to hardcode the PAT directly into your script, i.e.
replace PAT = os.environ["TYBA_PAT"] with PAT="your-pat-in-quotes"
Jupyter Notebook (preferred)
See the Jupyter notebook section above.