PyBD¶
A Python API to access the Bazean Postgres database
Example Usage¶
A simple Python script that gets the production data from 10 wells from the state of Texas operated by XOM:
from pybd import PyBD
db = PyBD(user='bazean_postgres_username', password='bazean_postgres_password')
db.set_fetch_size(10)
locations = db.get_well_locations_by_ticker_and_state('XOM', 'TX')
oil_production = []
for api in locations['apis'].values:
df = db.get_production_from_api(api)
oil_production += df['oil']
API Documentation¶
-
class
pybd.
PyBD
(user=None, password=None, subdomain='premium', schema='public')[source]¶ Class for querying Bazean database.
Parameters: - user (str) – Bazean database username, defaults to use the environment variable BAZEAN_POSTGRES_USERNAME if assigned
- password (str) – Bazean database password, defaults to use the environment variable BAZEAN_POSTGRES_PASSWORD if assigned
- subdomain (str) – URL subdomain, default is “premium”
- schema (str) – Postgres schema, default is “public”
-
get
(table, columns, **kwargs)[source]¶ General function to construct SQL query statement and retrieve columns of data
Parameters: - table (str) – SQL table name
- columns (tuple of str) – A tuple of column names to select
- **kwargs –
Arbitrary number of keyword arguments of the form key=value. These would be expected to construct the WHERE portion of the SQL statement with a logical AND operation. For example:
db = PyBD() db.get('production_all', ('apis',), state='KS', api='15001016610000')
and would result in the query string:
SELECT apis FROM production_all WHERE state='KS' AND api='15001016610000'
In this simple case, the function would return a list [[‘15001016610000’]].
Returns: Nested list of returned columns of data from the SQL query.
Return type: (list)
-
get_production_from_api
(api)[source]¶ Returns the total production histories for a given API number
Parameters: api (str) – API number for requested well production histories Returns: Pandas DataFrame. Return type: (DataFrame)
-
get_tickers_by_state
(state)[source]¶ Returns the stock tickers (actual or assigned) of companies that operate/own wells in a given state.
Parameters: state (str) – The two letter postal code of a state, i.e. “TX” or “NM” Returns: A list containing the stock tickers. Missing entries query entries with None are ommitted. Return type: (list of str)