Skip to main content

The Nuvolos Python library for database connectivity, internal PyODBC-based version

Project description

Nuvolos connector for Python (PyODBC version, for internal use)

This package allows you to read table data from Nuvolos and upload Pandas dataframes as tables.

Loading data to Nuvolos

This package provides a to_sql function, which bulk loads a Pandas DataFrame to Nuvolos. This function is able to load large DataFrames quickly and efficiently, using the database engine's bulk data ingestion process. It is based on the write_pandas function of the snowflake-connector-python package.

Note:

It is recommended to use lowercase DataFrame column and index names. Uppercase or mixed-case DataFrame column/index names will result in case-sensitive table name and column names, which can be queried with quoted identifiers.

Syntax:

def to_sql(
    df,
    name,
    con,
    database=None,
    schema=None,
    if_exists="fail",
    index=True,
    index_label=None,
    nanoseconds=False,
):
    """
    Load a DataFrame to the specified table in the database.
    Creates the table if it doesn't yet exist, with TEXT/FLOAT/DATE/TIMESTAMP columns as required.
    The name will be case sensitive (quoted) if it contains lowercase or special characters or is a reserved keyword.
    Based on the write_pandas function of snowflake-connector-python:
    https://docs.snowflake.com/en/user-guide/python-connector-api.html#write_pandas
    :param df: The Pandas DataFrame to insert/stage as a table.
    :param name: The name of the database table. It will only be quoted and case sensitive if it contains keywords or special chars.
    :param con: The pre-opened database Connection to use.
    :param database: The name of the database to which data will be inserted.
    :param schema: The name of the schema to which data will be inserted.
    :param if_exists: How to behave if the table already exists. {‘fail’, ‘replace’, ‘append’}, default ‘fail’
             * fail: Raise a ValueError.
             * replace: Drop the table before inserting new values.
             * append: Insert new values to the existing table.
    :param index: bool, default True: Write DataFrame index as a column. Uses index_label as the column name in the table.
    :param index_label: Column label for index column(s). If None is given (default) and index is True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex.
    :param nanoseconds: If True, nanosecond timestamps will be used to upload the data. Limits timestamp range from 1677-09-21 00:12:43.145224192 to 2262-04-11 23:47:16.854775807. 
    :return: Returns the COPY INTO command's results to verify ingestion in the form of a tuple of whether all chunks were
        ingested correctly, # of chunks, # of ingested rows, and ingest's output.
    """

Usage example:

In this example, the DataFrame will be loaded to a table named "quotes_AND_index", which is a case-sensitive name.

from nuvolos import get_connection, to_sql
import pandas as pd

conn = get_connection()
to_sql(
    df=df,
    name="lowercase_is_best",
    con=conn,
    index=True,
    index_label="seq_num",
    if_exists="replace"
)
df_r = pd.read_sql('SELECT * FROM lowercase_is_best;', con=conn, index_col="seq_num")
df_c = df.compare(df_r) # Will be an empty DataFrame, as there are no differences.

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

nuvolos_odbc-0.5.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

nuvolos_odbc-0.5.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file nuvolos_odbc-0.5.0.tar.gz.

File metadata

  • Download URL: nuvolos_odbc-0.5.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.9

File hashes

Hashes for nuvolos_odbc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2cab5271dc94fb3ea847828a3ba6d95af2233094b9394698910a962b48dad91e
MD5 801e3cd7d92e92dbcb1c890e1e9450b8
BLAKE2b-256 d8f600cb94ae29f0bfe0a9a66eaf4b3f4f5ec4468fc554808ddf6d5c3a032471

See more details on using hashes here.

File details

Details for the file nuvolos_odbc-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: nuvolos_odbc-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.9

File hashes

Hashes for nuvolos_odbc-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 032a9746365afdbfd75d15cd617dc0c4e16d82522835251c318302d5604e2818
MD5 024c45cef6f24632f31b65f7894a1317
BLAKE2b-256 8808ae90bf5dd08129c5d0a42755448692dc0ec33b90683c18e8cd6aab65415c

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