Skip to main content

A utility to run BCP bulk inserts from a Pandas DataFrame.

Project description

Python BCP Utility (py-bcp-utils)

PyPI version License: MIT

A simple Python utility to run the SQL Server bcp (Bulk Copy Program) command using a Pandas DataFrame as the source.

This package acts as a thin wrapper, saving the DataFrame to a temporary CSV file and then calling the bcp command-line tool to perform a high-speed bulk insert.

Key Features

  • Bulk insert pandas.DataFrame objects directly into SQL Server.
  • Uses the highly performant, native bcp command-line tool.
  • Supports both SQL Server Authentication (username/password) and Trusted Connections (Windows Authentication).
  • Simple, single-function API.

Requirements

  1. Python 3.8+
  2. pandas (will be installed automatically)
  3. bcp Utility: The SQL Server bcp command-line utility must be installed on your system and available in your shell's PATH.
    • On Windows, this is typically installed with SQL Server Management Studio (SSMS) or the Microsoft Command Line Utilities for SQL Server.

💾 Installation

Once the package is published to the real PyPI, you can install it with:

pip install py-bcp-utils

Usage Example

Here is a complete example of how to import and use the function.

import pandas as pd
import logging
from bcp_utils import bulk_insert_bcp

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

data = {
    'column1': [1, 2, 3],
    'column2': ['apple', 'banana', 'orange'],
    'column3': [10.5, 20.1, 30.2]
}
df = pd.DataFrame(data)

DB_SERVER = "YourServerName,1433"
DB_TABLE = "YourDatabase.dbo.YourTable"
TEMP_CSV = "temp_bcp_data.csv"
ERROR_LOG = "bcp_error.log"

try:
    logging.info("Attempting insert with SQL Server login...")
    bulk_insert_bcp(
        df=df,
        target_table=DB_TABLE,
        db_server_port=DB_SERVER,
        temp_file=TEMP_CSV,
        error_log_file=ERROR_LOG,
        username="your_sql_user",
        password="your_sql_password"
    )

    logging.info("✅ Successfully inserted data!")

except Exception as e:
    logging.error(f"Data insert failed: {e}")

License

This project is licensed under the MIT License.

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

py_bcp_utils-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

py_bcp_utils-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file py_bcp_utils-0.1.0.tar.gz.

File metadata

  • Download URL: py_bcp_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for py_bcp_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5286d3a12887ce7b5c79ad9f9aa893fbd7a0c7cf8ddacfd08c7e3dc49f6c0c06
MD5 8c129a7ec0b6dc93b47ba54fc424a073
BLAKE2b-256 5779b89c2704c54ac022ccf1889ad3f83e847c6f44959550878f0c81e4b270dd

See more details on using hashes here.

File details

Details for the file py_bcp_utils-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_bcp_utils-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for py_bcp_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddd1b3da4912ebe6b5cc206ecd5dd9801893cc5ef2303e03be7e2b2b236e2ecd
MD5 22d3ec20dc309487cded3039f6fad6f0
BLAKE2b-256 9b3dc16f03d82a927a9d892456a28b8035204f3987c055a84acb85cc06339c6a

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