SPGCI Python Library
Python Client for the S&P Global Commodity Insights API.
Looking for more examples? Check out our Notebook Gallery.
Installation
Requires Python >= 3.9.0.
pip install spgci
Getting Started
import spgci as ci
ci.set_credentials(<username>, <password>)
mdd = ci.MarketData()
symbols = ["PCAAS00", "PCAAT00"]
mdd.get_assessments_by_symbol_current(symbol=symbols)
Alternatively, you can set your credentials via Environment Variables and omit the set_credentials
call:
Environment Variable | Description |
---|
SPGCI_USERNAME | Your Username |
SPGCI_PASSWORD | Your Password |
Features
- Automatically generates token prior to making request.
- Returns data as a pandas DataFrame (set
raw=False
to get the raw request.response
object). - Can auto-paginate response and concatenates into a single DataFrame (set
paginate=True
to enable). - Sets datatype for
date
and datetime
fields in DataFrame. - Composes nicely with native python/pandas types. Arguments support
lists
and pd.Series
which are automatically converted into filter expressions.
Datasets Supported
Market Data
import spgci as ci
mdd = ci.MarketData()
mdd.get_symbols(commodity="Crude oil")
mdd.get_mdcs(subscribed_only=True)
mdd.get_assessments_by_mdc_current(mdc="ET")
Forward Curves
import spgci as ci
fc = ci.ForwardCurves()
fc.get_curves(
commodity=["Benzene", "Crude oil"],
derivative_maturity_frequency="Month"
)
fc.get_assessments(curve_code=["CN003", "CN006"])
Energy Price Forecast
import spgci as ci
epf = ci.EnergyPriceForecast()
epf.get_prices_shortterm(symbol="PCAAS00", month=[10, 11, 12])
epf.get_prices_longterm(year=[2020, 2021], sector="Energy Transition", delivery_region="Europe")
EWindow Market Data
import spgci as ci
from datetime import date
ewmd = ci.EWindowMarketData()
ewmd.get_markets()
d = date(2023,2,13)
ewmd.get_botes(market=["EU BFOE", "US MidWest"], order_time=d)
World Oil Supply
import spgci as ci
wos = ci.WorldOilSupply()
countries = wos.get_reference_data(type=wos.RefTypes.Countries)
wos.get_ownership(country=countries['countryName'][:3], year=2040)
World Refinery Database
import spgci as ci
wrd = ci.WorldRefineryData()
wrd.get_yields(year=2020, owner="BP")
ref = wrd.get_reference_data(type=wrd.RefTypes.Refineries)
az = ref[ref['Name'].str.contains("Al-Zour")]
wrd.get_runs(refinery_id=az["Id"])
wrd.get_outages(refinery_id=245)
Insights
import spgci as ci
ni = ci.Insights()
ni.get_stories(q="Suez", content_type=ni.ContentType.MarketCommentary)
ni.get_subscriber_notes(q="Naptha")
ni.get_heards(q="Steel", content_type=ni.HeardsContentType.Heard, geography=['Europe', 'Middle East'], strip_html=True)
Global Oil Demand
import spgci as ci
od = ci.GlobalOilDemand()
od.get_demand(country="Cambodia", product=["Naphtha", "Ethane"])
products = od.get_reference_data(type=od.RefTypes.Products)
od.get_demand(product=products["productName"][:3], year_gte=2023)
od.get_demand_archive(scenario_id=150, country="Norway")
North America Natural Gas Analytics
import spgci as ci
from datetime import date
ng = ci.NANaturalGasAnalytics()
ng.get_pipelines(state="NJ", facility_type="Interconnect")
ng.get_pipelines(pipeline_name="Algonquin")
ng.get_pipeline_flows(pipeline_id=32)
d = date(2023, 7, 24)
ng.get_pipeline_flows(nomination_cycle="I2", gasdate=d)
Global Integrated Energy Model
import spgci as ci
giem = ci.GlobalIntegratedEnergyModel()
giem.get_demand(country="Cambodia", product=["Naphtha", "Ethane"])
giem.get_demand_archive(scenario_id=559, country="Cambodia", product=["Naphtha", "Ethane"])
giem.get_reference_data(type=giem.RefTypes.Products)
Refining Margins & Crude Arbitrage
import spgci as ci
af = ci.Arbflow()
af.get_margins_catalog(location_id = 34, crude_symbol="AAQZB00")
af.get_margins_data(margin_id=229, margin_date='2023-08-16')
af.get_arbitrage(margin_id=[220,330], base_margin_id=1514, frequency_id=2)
af.get_reference_data(type=af.RefTypes.Locations)
LNG Global Analytics
import spgci as ci
lng = ci.LNGGlobalAnalytics()
lng.get_tenders(country_name="United States", paginate=True)
lng.get_tenders(contract_type="FOB", contract_option="Sell")
lng.get_liquefaction_projects()
lng.get_outages(liquefaction_project_name="ADNOC LNG")
lng.get_netbacks(date_gt="2024-01-01", import_geography="Brazil")
lng.get_supply_forecast_current(export_market="Indonesia")
lng.get_demand_forecast_history(import_market="Japan", month="2024-12-01")
lng.get_cargo_trips(trade_route="Suez Canal", date_loaded_gte="2024-01-01")
lng.get_cargo_events_partial_reexport()
lng.get_assets_contracts_offtake_contracts(assumed_destination="Japan")
lng.get_assets_contracts_liquefaction_trains(train_status=["Existing","Under Construction"])
lng.get_gas_demand(market=["United States", "Mexico"], period_type="Monthly")
lng.get_power_generation(
market=["India", "Pakistan", "Bangladesh"],
source="Power Generation By Fuel",
period_type="Monthly",
paginate=True,
)
Crude Analytics
import spgci as ci
ca = ci.CrudeAnalytics()
ca.get_country_scores(status="Current")
ca.get_country_scores(country="United States")
ca.get_country_total_scores()
Weather
import spgci as ci
w = ci.Weather()
w.get_forecast(city="Boston")
w.get_forecast(market="United States", weather_date_gte="2024-01-01", weather_date_lte="2024-01-31")
w.get_actual(market="Hong Kong", paginate=True)
Structured Heards
import spgci as ci
sh = ci.StructuredHeards()
sh.get_markets()
sh.get_heards(market="Americas crude oil", heard_type="trade")
Chemicals Analysis and Forecasts
import spgci as ci
chem = ci.Chemicals()
chem.get_unique_values(dataset="production", columns=["commodity"])
chem.get_capacity_events(
event_begin_date_gt="2023-01-01", country="China", event_type=["expand", "startup"]
)
chem.get_capacity_to_consume(is_active=[True, False], commodity="Polybutadiene rubber")
chem.get_short_term_prices(commodity="Acetone", delivery_region="US Gulf Coast")
chem.get_outages(
start_date_gte="2023-01-01",
capacity_gte=500,
alert_status=['Confirmed']
)
European Gas Analytics
import spgci as ci
egp = ci.EUGasAnalytics()
egp.get_daily_flow_point_selection(
from_country="Norway",
gas_day_gte="2024-10-01",
gas_day_lte="2024-10-31",
uom="MCM",
direction="Net",
)
df = egp.get_overview_hub_balance(
gas_day_gte="2024-10-01",
gas_day_lte="2024-10-31",
average_type="Daily value",
hub="PEG",
uom="MCM",
)
df.pivot_table(
index=["hubFlowType", "hubSubFlowType"],
columns="dayMonthOrdinal",
values="quantity",
)
Oil and NGL Analytics
import spgci as ci
rp = ci.OilNGLAnalytics()
rp.get_arbflow_arbitrage(from_region="Persian Gulf", to_region="Japan")
rp.get_arbflow_arbitrage(commodity="Jet Fuel", concept="incentive")