Functionalities to interact with Google and Azure, and clean data
Project description
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
Installation
Commands
To install the latest version from main branch, use the following command:
pip install do-data-utils
You can install a specific version, for example,
pip install do-data-utils==2.1.0
Install in requirements.txt
You can also put this source in the requirements.txt.
# requirements.txt
do-data-utils==2.1.0
Available Subpackages
google– Utilities for Google Cloud Platform.azure– Utilities for Azure services.pathutils– Utilities related to paths.
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
with open('secrets/secret-manager-key.json', 'r') as f:
secret_info = json.load(f)
secret = get_secret(secret_info, project_id='my-secret-project-id', secret_id='gcs-secret-id-dev')
# 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
with open('secrets/secret-manager-key.json', 'r') as f:
secret_info = json.load(f)
secret = get_secret(secret_info, project_id='my-secret-project-id', secret_id='gcs-secret-id-dev')
# 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
with open('secrets/secret-manager-key.json', 'r') as f:
secret_info = json.load(f)
secret = get_secret(secret_info, project_id='my-secret-project-id', secret_id='gcs-secret-id-dev')
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)
secret = get_secret(secret_info, project_id='my-secret-project-id', secret_id='gbq-secret-id-dev')
# 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_info, project_id='my-secret-project-id', secret_id='databricks-secret-id-dev')
# Download from Databricks sql
query = 'select * from datadev.dsplayground.my_table'
df = databricks_to_df(query, secret, polars=False)
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)
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 do_data_utils-2.1.0.tar.gz.
File metadata
- Download URL: do_data_utils-2.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3396a3498a1dcfdd4caa8d7560c7306334705611a4c56eb11322917f2952fdd3
|
|
| MD5 |
a9c0ac1ae034b97435ff63a652fcf149
|
|
| BLAKE2b-256 |
65d12d5947cc53f5d8e24ba20d6b5f854ff3f8aabbec6d600cd2406ce0cdbeba
|
File details
Details for the file do_data_utils-2.1.0-py3-none-any.whl.
File metadata
- Download URL: do_data_utils-2.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0768b4bcb083372c829f64e8f0e53aa312d557ab2681606a62fdbecdc7c5ae63
|
|
| MD5 |
cadb15e57b6da38f3f8bca797b5734f8
|
|
| BLAKE2b-256 |
fe1298f9fce815f3ae81a792d18dc40b88e786376951f69d58c06dac00bfdaa5
|