Useful utilities for data IO operations, including Snowflake, S3, and SageMaker integrations.
Project description
bpx-dataio
Useful utilities for data IO operations, including Snowflake, S3, and SageMaker integrations.
Installation
pip install bpx-dataio
Note: All classes are available with the basic installation. The package uses boto3 for AWS/SageMaker interactions and does not require the sagemaker library (which would pull in torch ~111MB).
Classes
SnowflakeIO
Handles authentication and interaction with a Snowflake data warehouse using AWS Secrets Manager credentials.
from dataio import SnowflakeIO
# Initialize with default settings
sf = SnowflakeIO()
# Execute a query
df = sf.query("SELECT * FROM my_table LIMIT 10")
# Execute a command
sf.execute_command("CREATE TABLE IF NOT EXISTS my_table (id INT)")
PARAM_JSON_IO
Read and write parameters to JSON files.
from dataio import PARAM_JSON_IO
# Initialize with JSON file path
json_io = PARAM_JSON_IO("config.json")
# Read parameters
params = json_io.read_param_from_json()
# Write/update parameters
json_io.write_param_to_json({"key": "value"})
SAGEMAKER_INFO
Get SageMaker session and AWS information. Only works in SageMaker environments.
from dataio import SAGEMAKER_INFO
sm_info = SAGEMAKER_INFO(region='us-west-2', verbose=True)
session = sm_info.get_sagemaker_session()
role_arn = sm_info.get_execution_role()
DATAIO_S3
S3 operations for uploading and downloading data.
from dataio import DATAIO_S3
s3_io = DATAIO_S3()
# List objects in a bucket
objs = s3_io.list_bucket_objs("my-bucket", prefix="data/")
# Upload a file
s3_io.upload_file_to_bucket("local_file.csv", "my-bucket", "remote_file.csv")
# Upload a DataFrame
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3]})
s3_io.upload_dataframe_to_bucket(df, "my-bucket", "data.csv")
# Read a DataFrame from S3
df = s3_io.read_df_from_bucket("my-bucket", "data.csv")
SCALER
Custom scaler that applies scaling to each column independently, compatible with scikit-learn pipelines.
from dataio import SCALER
from sklearn.preprocessing import RobustScaler
import pandas as pd
scaler = SCALER(scaler=RobustScaler)
df = pd.DataFrame({"a": [1, 2, 3, 4, 5], "b": [10, 20, 30, 40, 50]})
# Fit and transform
df_scaled = scaler.fit_transform(df)
# Transform only
df_scaled = scaler.transform(df)
# Inverse transform
df_original = scaler.inverse_transform(df_scaled)
Requirements
- Python >= 3.7
- boto3 >= 1.26.0
- snowflake-connector-python[pandas] >= 3.0.0
- pandas >= 1.5.0
- numpy >= 1.23.0
- scikit-learn >= 1.0.0
Note: This package uses boto3 for AWS/SageMaker interactions and does not require the sagemaker library, avoiding the large torch dependency (~111MB).
Testing
After installation, you can run the test script to verify all classes work correctly:
python test_bpx_dataio.py
The test script will:
- Test all classes that don't require external services (PARAM_JSON_IO, SCALER)
- Attempt to test AWS/SageMaker classes (may be skipped if AWS credentials are not configured)
- Skip Snowflake tests if AWS Secrets Manager access is not available
License
MIT License
Author
Julian Liu
Project details
Release history Release notifications | RSS feed
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 bpx_dataio-0.1.1.tar.gz.
File metadata
- Download URL: bpx_dataio-0.1.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c96c7a065f1acd0346dc2404c7eb0d54c1b962e0d009493be6c5c734d37c4809
|
|
| MD5 |
c9ef71f88f980b7d26061c57eca3577d
|
|
| BLAKE2b-256 |
e8a3810d6e69310ba3255681ba7d6f994a033ee58b015a9b73515ba2320dec5e
|
File details
Details for the file bpx_dataio-0.1.1-py3-none-any.whl.
File metadata
- Download URL: bpx_dataio-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e95a0a426f40dd25479a5d065f730bd61097449df4e6a9b23464a7eca68d85a
|
|
| MD5 |
b8d1d634b014637351b7232718586b9b
|
|
| BLAKE2b-256 |
ef7c25ea9301b09b24ad957768154fe33966b9e6a7734330ed86e98a109fea1e
|