PyBD

https://travis-ci.org/daytum/PyBD.svg?branch=master https://coveralls.io/repos/github/daytum/PyBD/badge.svg?branch=master Documentation Status https://badge.fury.io/py/pybd.svg https://img.shields.io/badge/code%20style-black-000000.svg

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)
get_well_locations_by_ticker_and_state(ticker, state)[source]

Returns the latitude, longitude and API number of wells

Parameters:
  • ticker (str) – Company stock ticker, i.e. “XOM”
  • state (str) – The two letter postal code of a state, i.e. “TX” or “NM”
Returns:

Pandas DataFrame

Return type:

(DataFrame)

set_fetch_size(value)[source]

Sets the fetch size for database query methods i.e. get_ methods

Parameters:value (int or ‘all’) – fetch size, default is 50.

Indices and tables