A utility to run BCP bulk inserts from a Pandas DataFrame.
Project description
Python BCP Utility (py-bcp-utils)
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.DataFrameobjects directly into SQL Server. - Uses the highly performant, native
bcpcommand-line tool. - Supports both SQL Server Authentication (username/password) and Trusted Connections (Windows Authentication).
- Simple, single-function API.
Requirements
- Python 3.8+
pandas(will be installed automatically)bcpUtility: The SQL Serverbcpcommand-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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_bcp_utils-0.1.1.tar.gz.
File metadata
- Download URL: py_bcp_utils-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0888721d2bb03f024c11377596aa4be4fd74f223e8548d77c0b92138501c6d23
|
|
| MD5 |
571567ae8372fcde6b03e5e150c21a2f
|
|
| BLAKE2b-256 |
d379d3d891af659d472831cc3d66e6c6c7682db7cb6f19b1b0ce4f86ae60b7b1
|
File details
Details for the file py_bcp_utils-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_bcp_utils-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c451caad8a17b02a7f76eb7a22dd51e133002781263872778ecef015f1f6a9f2
|
|
| MD5 |
784c99c168a91277ab95caeddcdf2bcf
|
|
| BLAKE2b-256 |
7771a641723973206b1a7875cb823e5479b244442a52ebdd50381785008eea57
|