Skip to main content

Wrapper for financial database APIs & Snowpark

Project description

HongXiongMao Refuel

Toolbox for importing data from various financial sources; for a personal project so if you are here by accident I highly advise you look elsewhere.

Usage

There are no plans to go into any material depth here, so these are just notes to job my own memory.

Snowflake

Snowflake objects here specifically related to the snowflake-connector so connecting to a database. There are three main functions. rsa_token_stuff which returns pkb given a password string and private_key_file.p8 snowflake_connect which returns a snowflake-python-connector connection, snowflake_sql_engine returns an SQL Alchemy engine object. Not being a database pro, both seem to work but I favour the engine.

Both functions require the same inputs:

def snowflake_sql_engine(
    user_details: dict,                     # dictionary of required inputs
    method='rsa',                           # can be 'rsa' or 'user' 
    password: None | str = None,            # password if using rsa
    private_key_file: None | str = None     # file location of .p8 file if using RSA
    ):

To help there are also templates for the user_details:

SNOWFLAKE_RSA_USER_DETAILS_TEMPLATE = dict(
    user="USERNAME",
    password="",
    account="xx123455",
    region="eu-west-1",
    warehouse="LAB_SOMETHING_WH",
    database="LAB_SOMETHING",
    # schema="",)

As well as some helper functions check_compatibility tests a df vs. a snowflake table for compatability (could be a bit buggy) sql_append_with_drop_duplicates does as it says on the tin

Installation

Bloomberg API

To make Bloomberg calls, the blpapi package must be installed; we then extend the excellent xbbg package. Unfortunately, installing of blpapi can be a pain in the backside. I can't get pyproject.toml to correctly install blpapi as a dependency.

Using pip instruction from the Bloomberg website

python -m pip install --index-url=https://bcms.bloomberg.com/pip/simple blpapi

Poetry requires 2 steps

  1. Set up Bloomberg as a source,
  2. installing blpapi
poetry source add --priority=supplemental bloomberg https://bcms.bloomberg.com/pip/simple/
poetry add --source bloomberg blpapi

Snowflake SQL

In order to get snowflake connectors working we've had to install several additional packages. Snowflake is very picky about which versions of pyarrow etc... are installed and requires old versions.

snowflake-connector-python = "^3.2.0"
snowflake-sqlalchemy = "^1.5.0"
pyarrow = ">=10.0.1, <10.1.0"
cryptography = "^41.0.5"

Publishing to PyPi

I'm no pro at deploying packages to PyPi, so these are my notes for deployment of a poetry package. For reference, I followed this tutorial

Key points:

  • (PyPi account is required)[https://pypi.org/manage/account/#account-emails]
  • (Configure Poetry)[https://python-poetry.org/docs/repositories/#configuring-credentials]
  • poetry build
  • poetry publish
# configure API key
poetry config pypi-token.pypi <pypi-reallyREALLYllongKEY...>

# The build bit
(base) (hxm-refuel-py3.10) PS C:\Users\XXX\Documents\GitHub\hxm-refuel> poetry build

Building hxm-refuel (0.1.0)
  - Building sdist
  - Built hxm_refuel-0.1.0.tar.gz
  - Building wheel
  - Built hxm_refuel-0.1.0-py3-none-any.whl

# publishing bit
(base) (hxm-refuel-py3.10) PS C:\Users\T333208\Documents\GitHub\hxm-refuel> poetry publish

Publishing hxm-refuel (0.1.0) to PyPI
 - Uploading hxm_refuel-0.1.0-py3-none-any.whl 0%
 - Uploading hxm_refuel-0.1.0-py3-none-any.whl 85%
 - Uploading hxm_refuel-0.1.0-py3-none-any.whl 100%
 - Uploading hxm_refuel-0.1.0.tar.gz 0%
 - Uploading hxm_refuel-0.1.0.tar.gz 100%

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hxm_refuel-0.3.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hxm_refuel-0.3.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file hxm_refuel-0.3.1.tar.gz.

File metadata

  • Download URL: hxm_refuel-0.3.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Windows/10

File hashes

Hashes for hxm_refuel-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d0828f1fde8ab66c84d9705e46e81afc333e14238e2b41e28a42352065d92fcb
MD5 f1c2bf991be283a77f3f4d699b5cd19a
BLAKE2b-256 acbfcea61248bca72cb6aa9a96afb1ad812d0d9dc201da20e48d74290e9c7f69

See more details on using hashes here.

File details

Details for the file hxm_refuel-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: hxm_refuel-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Windows/10

File hashes

Hashes for hxm_refuel-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 877807e00cf4be46c2504328d933960d64964ae30a39e2982e79ec47659a9626
MD5 f0f6df1d28e8767ac9ee6e83032e49b4
BLAKE2b-256 705e08bd38a49106c6c1d8471c3ba491db45cf92983f427608110d9d6aff766c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page