Package: hxm-refuel
HongXiongMao RefuelToolbox for importing data from various financial sources;
for a personal project so if you are here by accident I highly advise you look elsewhere.UsageThere are no plans to go into any material depth here, so these are just notes to job my own memory.SnowflakeSnowflake objects here specifically related to the snowflake-connector so connecting to a database.
There are three main functions.rsa_token_stuffwhich returns pkb given a password string and private_key_file.p8snowflake_connectwhich returns a snowflake-python-connector connection,snowflake_sql_enginereturns 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 functionscheck_compatibilitytests a df vs. a snowflake table for compatability (could be a bit buggy)sql_append_with_drop_duplicatesdoes as it says on the tinInstallationBloomberg APITo make Bloomberg calls, theblpapipackage must be installed; we then extend the excellentxbbgpackage.
Unfortunately, installing ofblpapican be a pain in the backside.
I can't getpyproject.tomlto correctly installblpapias a dependency.Using pip instruction fromthe Bloomberg websitepython -m pip install --index-url=https://bcms.bloomberg.com/pip/simple blpapiPoetryrequires 2 stepsSet up Bloomberg as a source,installingblpapipoetry source add --priority=supplemental bloomberg https://bcms.bloomberg.com/pip/simple/
poetry add --source bloomberg blpapiSnowflake SQLIn 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 PyPiI'm no pro at deploying packages to PyPi, so these are my notes for deployment of a poetry package.
For reference, I followedthis tutorialKey points:(PyPi account is required)[https://pypi.org/manage/account/#account-emails](Configure Poetry)[https://python-poetry.org/docs/repositories/#configuring-credentials]poetry buildpoetry 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%