Skip to main content

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%

Metadata

Release files for hxm-refuel 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hxm-refuel 0.3.5
File Size Uploaded Provenance Actions
hxm_refuel-0.3.5.tar.gz 18.9 kB Without provenance Details for hxm_refuel-0.3.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hxm-refuel 0.3.5
File Interpreter ABI Platform Actions
hxm_refuel-0.3.5-py3-none-any.whl Python 3 none any Details for hxm_refuel-0.3.5-py3-none-any.whl

Total release size: 42.0 kB

Release files / hxm_refuel-0.3.5.tar.gz

Download URL hxm_refuel-0.3.5.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4f68bf4489b23b2906a667c82643681af04a9ea0f064258285fb079d01518cda
BLAKE2b-256 checksum
How to use checksums
41b54c5aac7672a91d39dfae117d5c8d4b88ab34d89a7c50f6604d2847fcebe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.7 Windows/10

Release files / hxm_refuel-0.3.5-py3-none-any.whl

Download URL hxm_refuel-0.3.5-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02a3e71dee3608c5fa9a7be22aa08ecc712667dd6cd65fcfddd698aac99ffbe5
BLAKE2b-256 checksum
How to use checksums
726e07c67b35c474b69ac0eccf866cd20b687c590f71ef33defdf78637a78c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.7 Windows/10

Security for hxm-refuel 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page