do-data-utils
This package provides you the functionalities to connect to different cloud sources and data cleaning functions. Package repo on PyPI: do-data-utils - PyPI
For a full list of functions, see the overview documentation.
Installation
Commands
To install the latest version from main branch, use the following command:
pip install do-data-utils
Available Subpackages
google– Utilities for Google Cloud Platform.azure– Utilities for Azure services.pathutils– Utilities related to paths.preprocessing– Utilities for data preprocessing.sharepoint- Utilities for interacting with Microsoft Sharepoint.
For a full list of functions, see the overview documentation.
Example Usage
The concept of using this revolves around the idea that:
- You keep service account JSON secrets (for cloud services) in GCP secret manager
- You have local JSON secret file for accessing the GCP secret manager
- Retrive the secret you want to interact with cloud platform from GCP secret manager
- Do your stuff...
GCS
Download
from do_data_utils.google import get_secret, gcs_to_df
# Load secret key and get the secret to access GCS
secret_path = 'secrets/secret-manager-key.json'
secret = get_secret(secret_id='gcs-secret-id-dev', secret=secret_path, as_json=True)
# Download a csv file to DataFrame
gcspath = 'gs://my-ai-bucket/my-path-to-csv.csv'
df = gcs_to_df(gcspath, secret, polars=False)
from do_data_utils.google import get_secret, gcs_to_dict
# Load secret key and get the secret to access GCS
secret_path = 'secrets/secret-manager-key.json'
secret = get_secret(secret_id='gcs-secret-id-dev', secret=secret_path, as_json=True)
# Download the content from GCS
gcspath = 'gs://my-ai-bucket/my-path-to-json.json'
my_dict = gcs_to_dict(gcspath, secret=secret)
Upload
from do_data_utils.google import get_secret, dict_to_json_gcs
# Load secret key and get the secret to access GCS
secret_path = 'secrets/secret-manager-key.json'
# No need to read in the secret info from version 2.3.0
with open('secrets/secret-manager-key.json', 'r') as f:
secret_info = json.load(f)
# you can pass in either dict or path to JSON in `secret` argument
secret = get_secret(secret_id='gcs-secret-id-dev', secret=secret_info, as_json=True)
my_setting_dict = {
'param1': 'abc',
'param2': 'xyz',
}
gcspath = 'gs://my-bucket/my-path-to-json.json'
dict_to_json_gcs(dict_data=my_setting_dict, gcspath=gcspath, secret=secret)
GBQ
from do_data_utils.google import get_secret, gbq_to_df
# Load secret key and get the secret to access GCS
with open('secrets/secret-manager-key.json', 'r') as f:
secret_info = json.load(f)
# you can pass in either dict or path to JSON in `secret` argument
secret = get_secret(secret_id='gbq-secret-id-dev', secret=secret_info, as_json=True)
# Query
query = 'select * from my-project.my-dataset.my-table'
df = gbq_to_df(query, secret, polars=False)
Azure/Databricks
from do_data_utils.azure import databricks_to_df
# Load secret key and get the secret to access GCS
with open('secrets/secret-manager-key.json', 'r') as f:
secret_info = json.load(f)
secret = get_secret(secret_id='databricks-secret-id-dev', secret=secret_info, as_json=True)
# Download from Databricks sql
query = 'select * from datadev.dsplayground.my_table'
df = databricks_to_df(query, secret, polars=False)
For more functions, see the overview documentation.
Path utils
from do_data_utils.pathutils import add_project_root
# Adds your root folder to sys.path,
# so you can do imports from the root directory
add_project_root(levels_up=1)
Preprocessing
from do_data_utils.preprocessing import clean_phone, clean_citizenid
phone_numbers = '090-123-4567|0912345678|0901234567-9'
phones_valid = clean_phone(phone_numbers) # Gets the valid phone numbers
citizenid = '0123456789012'
citizenid_cleaned = clean_citizenid(citizenid)
Sharepoint
import pandas as pd
from do_data_utils.google import get_secret
from do_data_utils.sharepoint import df_to_sharepoint
# Load secret key and get the secret to access GCS
secret_path = "secrets/secret-manager-key.json"
ms_secret = get_secret(secret_id="sharepoint-secret", secret=secret_path, as_json=True)
refresh_token = get_secret(
secret_id="sharepoint-refresh-token", secret=secret_path, as_json=False
)
# Example DataFrame
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
site = "your-site"
sharepoint_dir = "Shared Documents/some/path"
file_name = "output.xlsx" # or .csv if you wish
df_to_sharepoint(
df,
site=site,
sharepoint_dir=sharepoint_dir,
file_name=file_name,
secret=ms_secret,
refresh_token=refresh_token,
)
Metadata
Release files for do-data-utils 4.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| do_data_utils-4.2.1.tar.gz | 101.7 kB | Without provenance | Details for do_data_utils-4.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| do_data_utils-4.2.1-py3-none-any.whl | Python 3 | none | any | Details for do_data_utils-4.2.1-py3-none-any.whl |
Total release size: 127.3 kB
Release files / do_data_utils-4.2.1.tar.gz
| Download URL | do_data_utils-4.2.1.tar.gz |
|---|---|
| Size | 101.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76e6237b74bb8e9afa97eb416c14e01628ce49b79d22884546797e8d5a122385
|
|
BLAKE2b-256 checksum How to use checksums |
c63da0807e5e624ee576e02585c2da8f034b683d21a46b7320636aaf6dde5feb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Release files / do_data_utils-4.2.1-py3-none-any.whl
| Download URL | do_data_utils-4.2.1-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0dbadf7a8387d3bcdfd4818a9d76fb646647479d8f57d85275b3e7dfea4d458f
|
|
BLAKE2b-256 checksum How to use checksums |
819aecd40f9059404d478f999cfce3a8345d596f1403b5d466f12032a255c07b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Security for do-data-utils 4.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.