rdxz2-utill 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rdxz2-utill might be problematic. Click here for more details.
- rdxz2_utill-1.0.0/LICENSE +21 -0
- rdxz2_utill-1.0.0/PKG-INFO +168 -0
- rdxz2_utill-1.0.0/README.md +116 -0
- rdxz2_utill-1.0.0/pyproject.toml +47 -0
- rdxz2_utill-1.0.0/setup.cfg +4 -0
- rdxz2_utill-1.0.0/src/rdxz2_utill.egg-info/PKG-INFO +168 -0
- rdxz2_utill-1.0.0/src/rdxz2_utill.egg-info/SOURCES.txt +35 -0
- rdxz2_utill-1.0.0/src/rdxz2_utill.egg-info/dependency_links.txt +1 -0
- rdxz2_utill-1.0.0/src/rdxz2_utill.egg-info/entry_points.txt +2 -0
- rdxz2_utill-1.0.0/src/rdxz2_utill.egg-info/requires.txt +19 -0
- rdxz2_utill-1.0.0/src/rdxz2_utill.egg-info/top_level.txt +1 -0
- rdxz2_utill-1.0.0/src/utill/__init__.py +0 -0
- rdxz2_utill-1.0.0/src/utill/cmd/__init__.py +0 -0
- rdxz2_utill-1.0.0/src/utill/cmd/_bq.py +12 -0
- rdxz2_utill-1.0.0/src/utill/cmd/_conf.py +62 -0
- rdxz2_utill-1.0.0/src/utill/cmd/_enc.py +26 -0
- rdxz2_utill-1.0.0/src/utill/cmd/_main.py +8 -0
- rdxz2_utill-1.0.0/src/utill/cmd/_pg.py +15 -0
- rdxz2_utill-1.0.0/src/utill/cmd/utill.py +90 -0
- rdxz2_utill-1.0.0/src/utill/my_bq.py +358 -0
- rdxz2_utill-1.0.0/src/utill/my_const.py +18 -0
- rdxz2_utill-1.0.0/src/utill/my_csv.py +90 -0
- rdxz2_utill-1.0.0/src/utill/my_datetime.py +63 -0
- rdxz2_utill-1.0.0/src/utill/my_dict.py +12 -0
- rdxz2_utill-1.0.0/src/utill/my_encryption.py +52 -0
- rdxz2_utill-1.0.0/src/utill/my_env.py +66 -0
- rdxz2_utill-1.0.0/src/utill/my_file.py +60 -0
- rdxz2_utill-1.0.0/src/utill/my_gcs.py +117 -0
- rdxz2_utill-1.0.0/src/utill/my_input.py +11 -0
- rdxz2_utill-1.0.0/src/utill/my_json.py +62 -0
- rdxz2_utill-1.0.0/src/utill/my_mb.py +375 -0
- rdxz2_utill-1.0.0/src/utill/my_pg.py +159 -0
- rdxz2_utill-1.0.0/src/utill/my_queue.py +66 -0
- rdxz2_utill-1.0.0/src/utill/my_string.py +20 -0
- rdxz2_utill-1.0.0/src/utill/my_style.py +39 -0
- rdxz2_utill-1.0.0/src/utill/my_tunnel.py +42 -0
- rdxz2_utill-1.0.0/src/utill/my_xlsx.py +21 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Richard Dharmawan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rdxz2-utill
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A small example package
|
|
5
|
+
Author-email: Richard Dharmawan <richard.dharmawan@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Richard Dharmawan
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Classifier: Programming Language :: Python :: 3
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
29
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Classifier: Operating System :: OS Independent
|
|
32
|
+
Requires-Python: >=3.12
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: click==8.1.8
|
|
36
|
+
Requires-Dist: duckdb==1.1.3
|
|
37
|
+
Requires-Dist: humanize==4.11.0
|
|
38
|
+
Requires-Dist: loguru==0.7.3
|
|
39
|
+
Requires-Dist: paramiko==3.5.0
|
|
40
|
+
Requires-Dist: pydantic-settings==2.7.1
|
|
41
|
+
Requires-Dist: pydantic==2.10.6
|
|
42
|
+
Requires-Dist: requests==2.32.3
|
|
43
|
+
Requires-Dist: sshtunnel==0.4.0
|
|
44
|
+
Provides-Extra: google-cloud
|
|
45
|
+
Requires-Dist: google-cloud-bigquery==3.29.0; extra == "google-cloud"
|
|
46
|
+
Requires-Dist: google-cloud-storage==3.0.0; extra == "google-cloud"
|
|
47
|
+
Provides-Extra: postgresql
|
|
48
|
+
Requires-Dist: psycopg==3.2.2; extra == "postgresql"
|
|
49
|
+
Provides-Extra: pdf
|
|
50
|
+
Requires-Dist: PyPDF2==3.0.1; extra == "pdf"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# Using this library
|
|
54
|
+
|
|
55
|
+
Installation
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
pip install utill
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Usage syntax
|
|
62
|
+
|
|
63
|
+
```py
|
|
64
|
+
from utill.__MODULE__ import __OBJECT__
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example
|
|
68
|
+
|
|
69
|
+
```py
|
|
70
|
+
# Using the string module
|
|
71
|
+
from utill.my_string import generate_random_string
|
|
72
|
+
|
|
73
|
+
print(generate_random_string(16))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Initial set up
|
|
77
|
+
|
|
78
|
+
This package contains CLI command
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
utill conf init
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
# Additional extensions
|
|
85
|
+
|
|
86
|
+
Syntax
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
pip install utill[__EXTENSION_NAME__]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Extension list:
|
|
93
|
+
|
|
94
|
+
- google-cloud
|
|
95
|
+
- postgresql
|
|
96
|
+
- pdf
|
|
97
|
+
|
|
98
|
+
# Per module usages
|
|
99
|
+
|
|
100
|
+
## my_bq
|
|
101
|
+
|
|
102
|
+
Executing a query
|
|
103
|
+
|
|
104
|
+
```py
|
|
105
|
+
from utill.my_bq import BQ
|
|
106
|
+
|
|
107
|
+
# Initialize BigQuery client
|
|
108
|
+
bq = BQ()
|
|
109
|
+
|
|
110
|
+
# Execute a query, returns iterable QueryJob
|
|
111
|
+
job = bq.execute_query('...')
|
|
112
|
+
|
|
113
|
+
# Convert into list for quick data conversion
|
|
114
|
+
results = list(job)
|
|
115
|
+
|
|
116
|
+
# Iterate the results
|
|
117
|
+
for row in job:
|
|
118
|
+
# Do anything with the row
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Uploading CSV file into BigQuery table
|
|
122
|
+
|
|
123
|
+
```py
|
|
124
|
+
from utill.my_bq import BQ, Dtype, LoadStrategy
|
|
125
|
+
|
|
126
|
+
# Initialize BigQuery client
|
|
127
|
+
bq = BQ()
|
|
128
|
+
|
|
129
|
+
# Load the data
|
|
130
|
+
filename = '/path/to/file.csv' # Your local CSV file location
|
|
131
|
+
bq_table_fqn = 'project.dataset.table' # An FQN (fully qualified name) of a BigQuery table to export
|
|
132
|
+
columns = {
|
|
133
|
+
'col1': Dtype.INT64,
|
|
134
|
+
'col2': Dtype.STRING,
|
|
135
|
+
'col3': Dtype.DATE,
|
|
136
|
+
...
|
|
137
|
+
}
|
|
138
|
+
partition_col = 'col3' # Optional, for performance and cost optimization
|
|
139
|
+
cluster_cols = ['col1'] # Optional, for performance and cost optimization
|
|
140
|
+
load_strategy = LoadStrategy.APPEND # Optional, default to APPEND
|
|
141
|
+
bq.upload_csv(filename, bq_table_fqn, columns, partition_col, cluster_cols, load_strategy)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Exporting query into CSV
|
|
145
|
+
|
|
146
|
+
```py
|
|
147
|
+
from utill.my_bq import BQ
|
|
148
|
+
|
|
149
|
+
# Initialize BigQuery client
|
|
150
|
+
bq = BQ()
|
|
151
|
+
|
|
152
|
+
query = 'SELECT * FROM `project.dataset.table`' # The query to export
|
|
153
|
+
filename = '/path/to/file.csv' # Destination CSV file location
|
|
154
|
+
bq.download_csv(query, filename)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Exporting table into XLSX
|
|
158
|
+
|
|
159
|
+
```py
|
|
160
|
+
from utill.my_bq import BQ
|
|
161
|
+
|
|
162
|
+
# Initialize BigQuery client
|
|
163
|
+
bq = BQ()
|
|
164
|
+
|
|
165
|
+
bq_table_fqn = 'project.dataset.table' # An FQN (fully qualified name) of a BigQuery table to export
|
|
166
|
+
filename = '/path/to/file.xlsx' # Destination XLSX file location
|
|
167
|
+
bq.download_xlsx(src_table_fqn, dst_filename)
|
|
168
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Using this library
|
|
2
|
+
|
|
3
|
+
Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pip install utill
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Usage syntax
|
|
10
|
+
|
|
11
|
+
```py
|
|
12
|
+
from utill.__MODULE__ import __OBJECT__
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Example
|
|
16
|
+
|
|
17
|
+
```py
|
|
18
|
+
# Using the string module
|
|
19
|
+
from utill.my_string import generate_random_string
|
|
20
|
+
|
|
21
|
+
print(generate_random_string(16))
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Initial set up
|
|
25
|
+
|
|
26
|
+
This package contains CLI command
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
utill conf init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
# Additional extensions
|
|
33
|
+
|
|
34
|
+
Syntax
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pip install utill[__EXTENSION_NAME__]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Extension list:
|
|
41
|
+
|
|
42
|
+
- google-cloud
|
|
43
|
+
- postgresql
|
|
44
|
+
- pdf
|
|
45
|
+
|
|
46
|
+
# Per module usages
|
|
47
|
+
|
|
48
|
+
## my_bq
|
|
49
|
+
|
|
50
|
+
Executing a query
|
|
51
|
+
|
|
52
|
+
```py
|
|
53
|
+
from utill.my_bq import BQ
|
|
54
|
+
|
|
55
|
+
# Initialize BigQuery client
|
|
56
|
+
bq = BQ()
|
|
57
|
+
|
|
58
|
+
# Execute a query, returns iterable QueryJob
|
|
59
|
+
job = bq.execute_query('...')
|
|
60
|
+
|
|
61
|
+
# Convert into list for quick data conversion
|
|
62
|
+
results = list(job)
|
|
63
|
+
|
|
64
|
+
# Iterate the results
|
|
65
|
+
for row in job:
|
|
66
|
+
# Do anything with the row
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Uploading CSV file into BigQuery table
|
|
70
|
+
|
|
71
|
+
```py
|
|
72
|
+
from utill.my_bq import BQ, Dtype, LoadStrategy
|
|
73
|
+
|
|
74
|
+
# Initialize BigQuery client
|
|
75
|
+
bq = BQ()
|
|
76
|
+
|
|
77
|
+
# Load the data
|
|
78
|
+
filename = '/path/to/file.csv' # Your local CSV file location
|
|
79
|
+
bq_table_fqn = 'project.dataset.table' # An FQN (fully qualified name) of a BigQuery table to export
|
|
80
|
+
columns = {
|
|
81
|
+
'col1': Dtype.INT64,
|
|
82
|
+
'col2': Dtype.STRING,
|
|
83
|
+
'col3': Dtype.DATE,
|
|
84
|
+
...
|
|
85
|
+
}
|
|
86
|
+
partition_col = 'col3' # Optional, for performance and cost optimization
|
|
87
|
+
cluster_cols = ['col1'] # Optional, for performance and cost optimization
|
|
88
|
+
load_strategy = LoadStrategy.APPEND # Optional, default to APPEND
|
|
89
|
+
bq.upload_csv(filename, bq_table_fqn, columns, partition_col, cluster_cols, load_strategy)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Exporting query into CSV
|
|
93
|
+
|
|
94
|
+
```py
|
|
95
|
+
from utill.my_bq import BQ
|
|
96
|
+
|
|
97
|
+
# Initialize BigQuery client
|
|
98
|
+
bq = BQ()
|
|
99
|
+
|
|
100
|
+
query = 'SELECT * FROM `project.dataset.table`' # The query to export
|
|
101
|
+
filename = '/path/to/file.csv' # Destination CSV file location
|
|
102
|
+
bq.download_csv(query, filename)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Exporting table into XLSX
|
|
106
|
+
|
|
107
|
+
```py
|
|
108
|
+
from utill.my_bq import BQ
|
|
109
|
+
|
|
110
|
+
# Initialize BigQuery client
|
|
111
|
+
bq = BQ()
|
|
112
|
+
|
|
113
|
+
bq_table_fqn = 'project.dataset.table' # An FQN (fully qualified name) of a BigQuery table to export
|
|
114
|
+
filename = '/path/to/file.xlsx' # Destination XLSX file location
|
|
115
|
+
bq.download_xlsx(src_table_fqn, dst_filename)
|
|
116
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rdxz2-utill"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Richard Dharmawan", email="richard.dharmawan@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A small example package"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.12"
|
|
14
|
+
license = { file = "LICENSE" }
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"click==8.1.8",
|
|
24
|
+
"duckdb==1.1.3",
|
|
25
|
+
"humanize==4.11.0",
|
|
26
|
+
"loguru==0.7.3",
|
|
27
|
+
"paramiko==3.5.0",
|
|
28
|
+
"pydantic-settings==2.7.1",
|
|
29
|
+
"pydantic==2.10.6",
|
|
30
|
+
"requests==2.32.3",
|
|
31
|
+
"sshtunnel==0.4.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
utill = "utill.cmd.utill:main"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
google-cloud = [
|
|
39
|
+
"google-cloud-bigquery==3.29.0",
|
|
40
|
+
"google-cloud-storage==3.0.0",
|
|
41
|
+
]
|
|
42
|
+
postgresql = [
|
|
43
|
+
"psycopg==3.2.2",
|
|
44
|
+
]
|
|
45
|
+
pdf = [
|
|
46
|
+
"PyPDF2==3.0.1",
|
|
47
|
+
]
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rdxz2-utill
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A small example package
|
|
5
|
+
Author-email: Richard Dharmawan <richard.dharmawan@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Richard Dharmawan
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Classifier: Programming Language :: Python :: 3
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
29
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Classifier: Operating System :: OS Independent
|
|
32
|
+
Requires-Python: >=3.12
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: click==8.1.8
|
|
36
|
+
Requires-Dist: duckdb==1.1.3
|
|
37
|
+
Requires-Dist: humanize==4.11.0
|
|
38
|
+
Requires-Dist: loguru==0.7.3
|
|
39
|
+
Requires-Dist: paramiko==3.5.0
|
|
40
|
+
Requires-Dist: pydantic-settings==2.7.1
|
|
41
|
+
Requires-Dist: pydantic==2.10.6
|
|
42
|
+
Requires-Dist: requests==2.32.3
|
|
43
|
+
Requires-Dist: sshtunnel==0.4.0
|
|
44
|
+
Provides-Extra: google-cloud
|
|
45
|
+
Requires-Dist: google-cloud-bigquery==3.29.0; extra == "google-cloud"
|
|
46
|
+
Requires-Dist: google-cloud-storage==3.0.0; extra == "google-cloud"
|
|
47
|
+
Provides-Extra: postgresql
|
|
48
|
+
Requires-Dist: psycopg==3.2.2; extra == "postgresql"
|
|
49
|
+
Provides-Extra: pdf
|
|
50
|
+
Requires-Dist: PyPDF2==3.0.1; extra == "pdf"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# Using this library
|
|
54
|
+
|
|
55
|
+
Installation
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
pip install utill
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Usage syntax
|
|
62
|
+
|
|
63
|
+
```py
|
|
64
|
+
from utill.__MODULE__ import __OBJECT__
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example
|
|
68
|
+
|
|
69
|
+
```py
|
|
70
|
+
# Using the string module
|
|
71
|
+
from utill.my_string import generate_random_string
|
|
72
|
+
|
|
73
|
+
print(generate_random_string(16))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Initial set up
|
|
77
|
+
|
|
78
|
+
This package contains CLI command
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
utill conf init
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
# Additional extensions
|
|
85
|
+
|
|
86
|
+
Syntax
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
pip install utill[__EXTENSION_NAME__]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Extension list:
|
|
93
|
+
|
|
94
|
+
- google-cloud
|
|
95
|
+
- postgresql
|
|
96
|
+
- pdf
|
|
97
|
+
|
|
98
|
+
# Per module usages
|
|
99
|
+
|
|
100
|
+
## my_bq
|
|
101
|
+
|
|
102
|
+
Executing a query
|
|
103
|
+
|
|
104
|
+
```py
|
|
105
|
+
from utill.my_bq import BQ
|
|
106
|
+
|
|
107
|
+
# Initialize BigQuery client
|
|
108
|
+
bq = BQ()
|
|
109
|
+
|
|
110
|
+
# Execute a query, returns iterable QueryJob
|
|
111
|
+
job = bq.execute_query('...')
|
|
112
|
+
|
|
113
|
+
# Convert into list for quick data conversion
|
|
114
|
+
results = list(job)
|
|
115
|
+
|
|
116
|
+
# Iterate the results
|
|
117
|
+
for row in job:
|
|
118
|
+
# Do anything with the row
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Uploading CSV file into BigQuery table
|
|
122
|
+
|
|
123
|
+
```py
|
|
124
|
+
from utill.my_bq import BQ, Dtype, LoadStrategy
|
|
125
|
+
|
|
126
|
+
# Initialize BigQuery client
|
|
127
|
+
bq = BQ()
|
|
128
|
+
|
|
129
|
+
# Load the data
|
|
130
|
+
filename = '/path/to/file.csv' # Your local CSV file location
|
|
131
|
+
bq_table_fqn = 'project.dataset.table' # An FQN (fully qualified name) of a BigQuery table to export
|
|
132
|
+
columns = {
|
|
133
|
+
'col1': Dtype.INT64,
|
|
134
|
+
'col2': Dtype.STRING,
|
|
135
|
+
'col3': Dtype.DATE,
|
|
136
|
+
...
|
|
137
|
+
}
|
|
138
|
+
partition_col = 'col3' # Optional, for performance and cost optimization
|
|
139
|
+
cluster_cols = ['col1'] # Optional, for performance and cost optimization
|
|
140
|
+
load_strategy = LoadStrategy.APPEND # Optional, default to APPEND
|
|
141
|
+
bq.upload_csv(filename, bq_table_fqn, columns, partition_col, cluster_cols, load_strategy)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Exporting query into CSV
|
|
145
|
+
|
|
146
|
+
```py
|
|
147
|
+
from utill.my_bq import BQ
|
|
148
|
+
|
|
149
|
+
# Initialize BigQuery client
|
|
150
|
+
bq = BQ()
|
|
151
|
+
|
|
152
|
+
query = 'SELECT * FROM `project.dataset.table`' # The query to export
|
|
153
|
+
filename = '/path/to/file.csv' # Destination CSV file location
|
|
154
|
+
bq.download_csv(query, filename)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Exporting table into XLSX
|
|
158
|
+
|
|
159
|
+
```py
|
|
160
|
+
from utill.my_bq import BQ
|
|
161
|
+
|
|
162
|
+
# Initialize BigQuery client
|
|
163
|
+
bq = BQ()
|
|
164
|
+
|
|
165
|
+
bq_table_fqn = 'project.dataset.table' # An FQN (fully qualified name) of a BigQuery table to export
|
|
166
|
+
filename = '/path/to/file.xlsx' # Destination XLSX file location
|
|
167
|
+
bq.download_xlsx(src_table_fqn, dst_filename)
|
|
168
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/rdxz2_utill.egg-info/PKG-INFO
|
|
5
|
+
src/rdxz2_utill.egg-info/SOURCES.txt
|
|
6
|
+
src/rdxz2_utill.egg-info/dependency_links.txt
|
|
7
|
+
src/rdxz2_utill.egg-info/entry_points.txt
|
|
8
|
+
src/rdxz2_utill.egg-info/requires.txt
|
|
9
|
+
src/rdxz2_utill.egg-info/top_level.txt
|
|
10
|
+
src/utill/__init__.py
|
|
11
|
+
src/utill/my_bq.py
|
|
12
|
+
src/utill/my_const.py
|
|
13
|
+
src/utill/my_csv.py
|
|
14
|
+
src/utill/my_datetime.py
|
|
15
|
+
src/utill/my_dict.py
|
|
16
|
+
src/utill/my_encryption.py
|
|
17
|
+
src/utill/my_env.py
|
|
18
|
+
src/utill/my_file.py
|
|
19
|
+
src/utill/my_gcs.py
|
|
20
|
+
src/utill/my_input.py
|
|
21
|
+
src/utill/my_json.py
|
|
22
|
+
src/utill/my_mb.py
|
|
23
|
+
src/utill/my_pg.py
|
|
24
|
+
src/utill/my_queue.py
|
|
25
|
+
src/utill/my_string.py
|
|
26
|
+
src/utill/my_style.py
|
|
27
|
+
src/utill/my_tunnel.py
|
|
28
|
+
src/utill/my_xlsx.py
|
|
29
|
+
src/utill/cmd/__init__.py
|
|
30
|
+
src/utill/cmd/_bq.py
|
|
31
|
+
src/utill/cmd/_conf.py
|
|
32
|
+
src/utill/cmd/_enc.py
|
|
33
|
+
src/utill/cmd/_main.py
|
|
34
|
+
src/utill/cmd/_pg.py
|
|
35
|
+
src/utill/cmd/utill.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
click==8.1.8
|
|
2
|
+
duckdb==1.1.3
|
|
3
|
+
humanize==4.11.0
|
|
4
|
+
loguru==0.7.3
|
|
5
|
+
paramiko==3.5.0
|
|
6
|
+
pydantic-settings==2.7.1
|
|
7
|
+
pydantic==2.10.6
|
|
8
|
+
requests==2.32.3
|
|
9
|
+
sshtunnel==0.4.0
|
|
10
|
+
|
|
11
|
+
[google-cloud]
|
|
12
|
+
google-cloud-bigquery==3.29.0
|
|
13
|
+
google-cloud-storage==3.0.0
|
|
14
|
+
|
|
15
|
+
[pdf]
|
|
16
|
+
PyPDF2==3.0.1
|
|
17
|
+
|
|
18
|
+
[postgresql]
|
|
19
|
+
psycopg==3.2.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
utill
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
def _upload_csv(src_filename: str, dst_table_fqn: str, cols: list[tuple[str, str]], partition_col: str = None, cluster_cols: list[str] = None, project: str = None):
|
|
2
|
+
from ..my_bq import BQ
|
|
3
|
+
|
|
4
|
+
bq = BQ(project)
|
|
5
|
+
bq.upload_csv(src_filename, dst_table_fqn, {col: dtype for col, dtype in cols}, partition_col, cluster_cols)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _download_table(src_table_fqn: str, dst_filename: str, project: str):
|
|
9
|
+
from ..my_bq import BQ
|
|
10
|
+
|
|
11
|
+
bq = BQ(project)
|
|
12
|
+
bq.download_csv(f'SELECT * FROM {src_table_fqn}', dst_filename)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
def _init(mode: str):
|
|
2
|
+
from loguru import logger
|
|
3
|
+
|
|
4
|
+
from ..my_env import envs, init_pg_file, init_mb_file
|
|
5
|
+
|
|
6
|
+
match mode:
|
|
7
|
+
case 'google-cloud':
|
|
8
|
+
setattr(envs, 'GCP_PROJECT_ID', input('GCP_PROJECT_ID: '))
|
|
9
|
+
setattr(envs, 'GCS_BUCKET', input('GCS_BUCKET: '))
|
|
10
|
+
envs.write()
|
|
11
|
+
logger.info('Google cloud configuration initialized')
|
|
12
|
+
case 'postgresql':
|
|
13
|
+
init_pg_file()
|
|
14
|
+
logger.info('PostgreSQL connection file initialized')
|
|
15
|
+
case 'metabase':
|
|
16
|
+
init_mb_file()
|
|
17
|
+
logger.info('Metabase connection file initialized')
|
|
18
|
+
case _:
|
|
19
|
+
logger.warning(f'Mode \'{mode}\' not recognized')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _list(module: str = None):
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
from loguru import logger
|
|
27
|
+
|
|
28
|
+
from ..my_env import envs, PG_FILENAME, MB_FILENAME
|
|
29
|
+
from ..my_string import mask
|
|
30
|
+
|
|
31
|
+
match module:
|
|
32
|
+
case 'postgresql':
|
|
33
|
+
if not os.path.exists(PG_FILENAME):
|
|
34
|
+
logger.error('PostgreSQL configuraiton not exists')
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
config: dict = json.loads(open(PG_FILENAME, 'r').read())
|
|
38
|
+
for k, v in config.items():
|
|
39
|
+
print(k)
|
|
40
|
+
for k2, v2 in v.items():
|
|
41
|
+
print(f'\t{k2} = {mask(str(v2)) if k2 in ("password", ) else v2}')
|
|
42
|
+
|
|
43
|
+
case 'metabase':
|
|
44
|
+
if not os.path.exists(MB_FILENAME):
|
|
45
|
+
logger.error('Metabase configuration not exists')
|
|
46
|
+
return
|
|
47
|
+
|
|
48
|
+
config: dict = json.loads(open(MB_FILENAME, 'r').read())
|
|
49
|
+
for k, v in config.items():
|
|
50
|
+
print(f'{k} = {mask(str(v)) if k in ("api_key", ) else v}')
|
|
51
|
+
case _:
|
|
52
|
+
for env in envs.model_fields:
|
|
53
|
+
print(f'{env} = {getattr(envs, env)}')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _set(vars: list[tuple[str, str]]):
|
|
57
|
+
from ..my_env import envs
|
|
58
|
+
|
|
59
|
+
for k, v in vars:
|
|
60
|
+
setattr(envs, k, v)
|
|
61
|
+
|
|
62
|
+
envs.write()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
def _encrypt(src: str, password: str, output: str = None, force: bool = False):
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
# Get the password string from file, if exists
|
|
5
|
+
path_password = Path(password).expanduser()
|
|
6
|
+
if path_password.exists():
|
|
7
|
+
if not path_password.is_file():
|
|
8
|
+
raise ValueError(f'Password path is not a file: {password}')
|
|
9
|
+
else:
|
|
10
|
+
password = open(path_password.as_posix(), 'r').read().strip()
|
|
11
|
+
|
|
12
|
+
path_src = Path(src).expanduser()
|
|
13
|
+
if path_src.exists():
|
|
14
|
+
if path_src.is_dir():
|
|
15
|
+
raise ValueError(f'Source file is a directory: {src}')
|
|
16
|
+
|
|
17
|
+
# Do encryption
|
|
18
|
+
from ..my_encryption import encrypt_file
|
|
19
|
+
if output:
|
|
20
|
+
encrypt_file(path_src.as_posix(), password, dst_filename=output, overwrite=force)
|
|
21
|
+
else:
|
|
22
|
+
print(encrypt_file(path_src.as_posix(), password))
|
|
23
|
+
else:
|
|
24
|
+
# Do encryption
|
|
25
|
+
from ..my_encryption import encrypt_string
|
|
26
|
+
print(encrypt_string(src, password))
|