berryworld 1.0.0.179222__py3-none-any.whl → 1.0.0.180131__py3-none-any.whl

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.
berryworld/__init__.py CHANGED
@@ -6,7 +6,7 @@ from .pickle_management import PickleManagement
6
6
  from .postgres_connection import Postgresql
7
7
  from .email_logging import EmailLogging
8
8
  from .verify_keys import Verify
9
- from .credentials import PostgresCredentials, SQLCredentials, BCCredentials, CDSCredentials, SharePointCredentials, \
9
+ from .credentials import PostgresCredentials, SnowflakeCredentials, SQLCredentials, BCCredentials, CDSCredentials, SharePointCredentials, \
10
10
  WebServiceCredentials, MicrosoftTeamsCredentials
11
11
  from .persistent_storage import PersistentStorage
12
12
  from .generate_env import EnvVariables
@@ -23,3 +23,4 @@ from .microsoft_teams import MicrosoftTeams
23
23
  from .vivantio import Vivantio
24
24
  from .teams_logging import TeamsLogging
25
25
  from .vivantio_logging import VivantioLogging
26
+ from .snowflake_conn import SnowflakeConn
berryworld/credentials.py CHANGED
@@ -253,3 +253,23 @@ class MicrosoftTeamsCredentials:
253
253
 
254
254
  except ValueError as e:
255
255
  raise ValueError("Variable %s not found" % str(e))
256
+
257
+
258
+ class SnowflakeCredentials:
259
+ def __init__(self, db_name):
260
+ if db_name is None:
261
+ raise ValueError("Please provide a value for db_name")
262
+ self.db_name = db_name
263
+
264
+ def simple_creds(self):
265
+ try:
266
+ account = os.environ.get("SNOWFLAKE_" + self.db_name.upper() + '_ACCOUNT')
267
+ user_name = os.environ.get("SNOWFLAKE_" + self.db_name.upper() + '_USERNAME')
268
+ password = os.environ.get("SNOWFLAKE_" + self.db_name.upper() + '_PASSWORD')
269
+
270
+ return {
271
+ 'account': account,
272
+ 'user_name': user_name,
273
+ 'password': password}
274
+ except ValueError as e:
275
+ raise ValueError("Variable %s not found" % str(e))
@@ -0,0 +1,77 @@
1
+ import pandas as pd
2
+ import snowflake.connector
3
+ from .credentials import SnowflakeCredentials
4
+
5
+ pd.set_option('future.no_silent_downcasting', True)
6
+
7
+
8
+ class SnowflakeConn:
9
+ def __init__(self, server_creds=None, **kwargs):
10
+ """ Initialize the class
11
+ -----------------------------
12
+ server_creds = {
13
+ "account": "",
14
+ "db_name": "",
15
+ "user_name": "",
16
+ "password": ""
17
+ }
18
+
19
+ -----------------------------
20
+ :param server_creds: Dictionary containing the info to connect to the Server
21
+ :param kwargs: Additional parameters to be passed to the connection
22
+ """
23
+
24
+ self.conn_str = None
25
+ self.conn = None
26
+
27
+ if kwargs != {}:
28
+ try:
29
+ db = kwargs['db_name']
30
+ server_creds = SnowflakeCredentials(db).simple_creds()
31
+ except KeyError:
32
+ raise KeyError('Please provide a valid db_name and server_type')
33
+
34
+ self.db = kwargs['db_name']
35
+ self.user = server_creds['user_name']
36
+ self.pw = server_creds['password']
37
+ self.account = server_creds['account']
38
+
39
+ if self.user and self.pw and self.account:
40
+ self.connect()
41
+
42
+ def connect(self):
43
+ """ Open the connection to Snowflake """
44
+ self.conn = snowflake.connector.connect(
45
+ user=self.user,
46
+ password=self.pw,
47
+ account=self.account,
48
+ database=self.db)
49
+
50
+ def close(self):
51
+ """ Close the connection to Snowflake """
52
+ self.conn.close()
53
+
54
+ def query(self, sql_query):
55
+ """ Read data from Snowflake according to the sql_query
56
+ -----------------------------
57
+ query_str = "SELECT * FROM %s" & table
58
+ con_.query(query_str)
59
+ -----------------------------
60
+ :param sql_query: Query to be sent to Snowflake
61
+ :return: DataFrame gathering the requested data
62
+ """
63
+ cursor = None
64
+ self.connect()
65
+ try:
66
+ cursor = self.conn.cursor()
67
+ cursor.execute(sql_query)
68
+ rows = cursor.fetchall()
69
+ col_names = [desc[0] for desc in cursor.description]
70
+ result = pd.DataFrame(rows, columns=col_names)
71
+ return result
72
+ except Exception as e:
73
+ raise Exception(e)
74
+ finally:
75
+ if cursor:
76
+ cursor.close()
77
+ self.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: berryworld
3
- Version: 1.0.0.179222
3
+ Version: 1.0.0.180131
4
4
  Summary: Handy classes to improve ETL processes
5
5
  Home-page: https://www.berryworld.com
6
6
  Author: BerryWorld ltd
@@ -1,10 +1,10 @@
1
- berryworld/__init__.py,sha256=QvrKku17Q0ns8sDSVnN0qp_clb4W3tKyzVNMyq0RatI,1077
1
+ berryworld/__init__.py,sha256=MMGWZ2WI82CgxWapFBsC3913rb3vspOWEQwAa8yMSTw,1141
2
2
  berryworld/aks_logs.py,sha256=Gb2_cokiZbEX01Yoptd0MxpDociaug-GrXdwliyxFBo,2293
3
3
  berryworld/allocation_solver.py,sha256=asFtaCAze6-eHUGWXA0kAp67UBS-Upj1KKdrVLj_ttQ,8513
4
4
  berryworld/app_logs.py,sha256=MKzKPYd3JuPfOQNAapIgaeZeFHw1z_w2mbn9I6QCADE,4180
5
5
  berryworld/app_logs_query.py,sha256=U94b-z3X9cuY_KFozupUcfaYciXWBn7p_RHkoRsfROU,4376
6
6
  berryworld/cache_data.py,sha256=AWAhV4PPkilZ4Xb1pUXuuu6UdHICAx8QqDtb9rVnjDM,2254
7
- berryworld/credentials.py,sha256=SeBLFqgadtUZclV1WbUC4uqI6xkcBlpV8miuifc8oqY,10290
7
+ berryworld/credentials.py,sha256=L70ZzSNaS2mbHtSS8lb3iesd1XSwZNnUzGznlEKxlJY,11018
8
8
  berryworld/devops.py,sha256=BAsVonVwCXoApUOovkt-BCzwc6KnXjxRDGff_ejSGw8,9719
9
9
  berryworld/email_con.py,sha256=uSBzs_Ijz9pUPWt9e7U3TCB7i6q7hU1bB5vhsTB_tmw,14448
10
10
  berryworld/email_logging.py,sha256=LeSrTExhQhar49gJR2wGC1dS0lqsNpFl9pS3eYWqnuo,4936
@@ -17,6 +17,7 @@ berryworld/pickle_management.py,sha256=O49ojVtTqYCT510rVRTbZWWaur_-5q3HSVG03Azn8
17
17
  berryworld/postgres_connection.py,sha256=whKDnchd5Feqpmxpoh2vlyn36EKHR-dVEULYq0N_4wA,8287
18
18
  berryworld/power_automate.py,sha256=9rDuRy0v-Ttq-SThid4lOB_tD4ibkyEmobiROpa--g4,25414
19
19
  berryworld/sharepoint_con.py,sha256=TuH-Vxk1VxjTi7x80KFssf_J8YPLRXpV27RBaFZi37U,22254
20
+ berryworld/snowflake_conn.py,sha256=IHXU3Nm7USPjJOJVBJALShCMTTGjZUvfyQDt0jGHo5Q,2481
20
21
  berryworld/sql_conn.py,sha256=meDAf_92hNW5Zp5sv_PPeIUA8NDchaDtVN7zo77veIA,47491
21
22
  berryworld/teams_logging.py,sha256=8NwXyWr4fLj7W6GzAm2nRQCGFDxibQpAHDHHD24FrP8,6997
22
23
  berryworld/transportation_solver.py,sha256=gdlHRgl2wlp5EV0uhKIOYtkkbAlHaFHGktnMgvuENWE,5022
@@ -28,8 +29,8 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
29
  tests/test_allocation_config.py,sha256=e12l6fE9U57eSPS35g6ekJ_hol7-RHg89JV60_m1BlE,4633
29
30
  tests/test_handy_mix_config.py,sha256=Un56mz9KJmdn4K4OwzHAHLSRzDU1Xv2nFrONNuzOG04,2594
30
31
  tests/test_xml_parser.py,sha256=3QTlhFEd6KbK6nRFKZnc35tad6wqukTbe4QrFi8mr_8,859
31
- berryworld-1.0.0.179222.dist-info/LICENSE,sha256=vtkVCJM6E2af2gnsi2XxKPr4WY-uIbvzVLXieFND0UU,1074
32
- berryworld-1.0.0.179222.dist-info/METADATA,sha256=QgD_R8cGkJU0mNXoC8WvrwuDxfgC3RG1hFsKsA1HLMo,1091
33
- berryworld-1.0.0.179222.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
34
- berryworld-1.0.0.179222.dist-info/top_level.txt,sha256=GIZ5qy-P5oxfEH755vA1IMFeTVdX3-40JxMe6nOe5I8,17
35
- berryworld-1.0.0.179222.dist-info/RECORD,,
32
+ berryworld-1.0.0.180131.dist-info/LICENSE,sha256=vtkVCJM6E2af2gnsi2XxKPr4WY-uIbvzVLXieFND0UU,1074
33
+ berryworld-1.0.0.180131.dist-info/METADATA,sha256=sdYlHaDJngHPRoJ8A3DkALXRrUqcBkFswFeG39wkjE8,1091
34
+ berryworld-1.0.0.180131.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
35
+ berryworld-1.0.0.180131.dist-info/top_level.txt,sha256=GIZ5qy-P5oxfEH755vA1IMFeTVdX3-40JxMe6nOe5I8,17
36
+ berryworld-1.0.0.180131.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.1)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5