maxsciencelib 0.0.5__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.

Potentially problematic release.


This version of maxsciencelib might be problematic. Click here for more details.

@@ -0,0 +1 @@
1
+ from .leitura import *
@@ -0,0 +1,136 @@
1
+ import os
2
+ import sys
3
+ import warnings
4
+ import snowflake.connector
5
+ import pandas as pd
6
+ import polars as pl
7
+ import tableauserverclient as TSC
8
+ import io
9
+
10
+
11
+ def leitura_snowflake(
12
+ email_corporativo: str,
13
+ token_account: str,
14
+ query: str
15
+ ) -> pl.DataFrame:
16
+ """
17
+ Executa uma query no Snowflake e retorna um DataFrame Polars.
18
+
19
+ Parâmetros
20
+ ----------
21
+ email_corporativo : str
22
+ Email corporativo usado no login (externalbrowser)
23
+ token_account : str
24
+ Account do Snowflake
25
+ query : str
26
+ Query SQL a ser executada
27
+
28
+ Retorno
29
+ -------
30
+ pl.DataFrame
31
+ """
32
+
33
+ warnings.filterwarnings("ignore", message=".*keyring.*")
34
+
35
+ sys_stdout, sys_stderr = sys.stdout, sys.stderr
36
+
37
+ try:
38
+ sys.stdout = open(os.devnull, 'w')
39
+ sys.stderr = open(os.devnull, 'w')
40
+
41
+ conn = snowflake.connector.connect(
42
+ user=email_corporativo,
43
+ account=token_account,
44
+ database='MAXPAR',
45
+ schema='ESTATISTICA',
46
+ role='GL_SNOWFLAKE_ACESSO_MAX_CED_DADOS',
47
+ warehouse='WH_USE_CED',
48
+ authenticator='externalbrowser',
49
+ network_timeout=600
50
+ )
51
+
52
+ cursor = conn.cursor()
53
+ try:
54
+ cursor.execute(query)
55
+
56
+ # 🔥 Snowflake -> Arrow -> Polars
57
+ arrow_table = cursor.fetch_arrow_all()
58
+ df = pl.from_arrow(arrow_table)
59
+
60
+ finally:
61
+ cursor.close()
62
+
63
+ finally:
64
+ sys.stdout.close()
65
+ sys.stderr.close()
66
+ sys.stdout, sys.stderr = sys_stdout, sys_stderr
67
+
68
+ try:
69
+ conn.close()
70
+ except Exception:
71
+ pass
72
+
73
+ return df
74
+
75
+
76
+
77
+ def leitura_tableau(
78
+ nome_token: str,
79
+ token_acesso: str,
80
+ view_id: str
81
+ ) -> pl.DataFrame:
82
+ """
83
+ Lê uma view do Tableau Server e retorna um DataFrame Polars.
84
+
85
+ Parâmetros
86
+ ----------
87
+ nome_token : str
88
+ Nome do Personal Access Token do Tableau
89
+ token_acesso : str
90
+ Token de acesso pessoal do Tableau
91
+ view_id : str
92
+ ID da view no Tableau Server
93
+
94
+ Retorno
95
+ -------
96
+ pl.DataFrame
97
+ """
98
+
99
+ warnings.filterwarnings("ignore")
100
+
101
+ def tentar_conectar(url: str):
102
+ tableau_auth = TSC.PersonalAccessTokenAuth(
103
+ token_name=nome_token,
104
+ personal_access_token=token_acesso,
105
+ site_id=""
106
+ )
107
+ server = TSC.Server(url, use_server_version=True)
108
+ server.auth.sign_in(tableau_auth)
109
+ return server
110
+
111
+ server = None
112
+ try:
113
+ try:
114
+ server = tentar_conectar("http://tableau.autoglass.com.br/")
115
+ except Exception:
116
+ server = tentar_conectar("https://tableau.autoglass.com.br/")
117
+
118
+ if server is None:
119
+ raise ConnectionError("Não foi possível conectar ao Tableau Server.")
120
+
121
+ # Obter view
122
+ view_item = server.views.get_by_id(view_id)
123
+
124
+ # Exportar CSV da view
125
+ server.views.populate_csv(view_item)
126
+
127
+ csv_bytes = b"".join(view_item.csv)
128
+
129
+ # CSV → Polars (via Arrow)
130
+ df = pl.read_csv(io.BytesIO(csv_bytes))
131
+
132
+ return df
133
+
134
+ finally:
135
+ if server:
136
+ server.auth.sign_out()
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: maxsciencelib
3
+ Version: 0.0.5
4
+ Summary: Biblioteca de funções compartilhadas do time de Data Science da Maxpar
5
+ Author-email: Daniel Antunes <daniel.ant.cord@gmail.com>
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENCE
9
+ Requires-Dist: pandas>=1.5
10
+ Requires-Dist: numpy>=1.23
11
+ Requires-Dist: polars>=0.20.0
12
+ Requires-Dist: pyarrow>=14.0.0
13
+ Requires-Dist: snowflake-connector-python>=3.5.0
14
+ Requires-Dist: io
15
+ Requires-Dist: tableauserverclient
16
+ Dynamic: license-file
17
+
18
+ # MaxScienceLib
19
+
20
+ Biblioteca com funções aplicadas a rotina do cientista de dados na Maxpar
21
+
22
+ ## Como usar
23
+
24
+ Instale com:
25
+
26
+ ```bash
27
+ pip install maxscientelib
28
+ ```
29
+
30
+ Use no seu código:
31
+
32
+ ```python
33
+ from maxsciencelib import leitura_snowflake
34
+ ```
35
+
36
+ ## leitura-snowflake
37
+
38
+ Biblioteca Python para leitura de dados do **Snowflake** de forma simples, segura e performática, retornando os resultados diretamente como **DataFrame Polars**.
39
+
40
+ A biblioteca abstrai toda a complexidade de conexão, autenticação via `externalbrowser` e execução de queries, permitindo que o usuário execute consultas com apenas **uma função**.
41
+
42
+ ---
43
+
44
+ ### Funcionalidades
45
+
46
+ - Conexão automática com Snowflake via `externalbrowser`
47
+ - Execução de queries SQL
48
+ - Retorno direto em **Polars DataFrame**
49
+ - Uso nativo de **Apache Arrow** (alta performance)
50
+ - Silenciamento de logs e warnings internos
51
+ - Fechamento seguro de conexão e cursor
52
+
53
+
54
+ ### Requisitos
55
+
56
+ - Python **3.11+** (recomendado)
57
+ - Acesso ao Snowflake configurado no navegador
58
+
59
+ ### Dependências
60
+
61
+ ```bash
62
+ pip install snowflake-connector-python polars pyarrow
63
+ ```
64
+
65
+ ### Uso básico
66
+
67
+ ```python
68
+ from leitura_snowflake import leitura_snowflake
69
+
70
+ query = """
71
+ SELECT *
72
+ FROM MINHA_TABELA
73
+ LIMIT 1000
74
+ """
75
+
76
+ df = leitura_snowflake(
77
+ email_corporativo="nome.sobrenome@empresa.com",
78
+ token_account="abc123.us-east-1",
79
+ query=query
80
+ )
81
+
82
+ df.head()
83
+ ```
84
+
85
+ O retorno será um objeto:
86
+
87
+ ```python
88
+ polars.DataFrame
89
+ ```
90
+
91
+ | Parâmetro | Tipo | Descrição |
92
+ | ------------------- | ----- | ------------------------------------------------- |
93
+ | `email_corporativo` | `str` | Email corporativo utilizado no login do Snowflake |
94
+ | `token_account` | `str` | Identificador da conta Snowflake |
95
+ | `query` | `str` | Query SQL a ser executada |
96
+
97
+
98
+ ---
99
+
100
+ ## leitura-tableau
101
+
102
+ Biblioteca Python para leitura de dados do **Tableau Server** de forma simples, segura e performática, retornando os resultados diretamente como **DataFrame Polars**.
103
+
104
+ A biblioteca abstrai toda a complexidade de autenticação via **Personal Access Token**, conexão com o Tableau Server (HTTP/HTTPS) e download da view, permitindo que o usuário consuma dados com apenas **uma função**.
105
+
106
+ ---
107
+
108
+ ### Funcionalidades
109
+
110
+ * Autenticação via **Personal Access Token (PAT)**
111
+ * Conexão automática com Tableau Server (fallback HTTP → HTTPS)
112
+ * Download de views diretamente do Tableau
113
+ * Retorno direto em **Polars DataFrame**
114
+ * Leitura eficiente de CSV em memória
115
+ * Silenciamento de warnings internos
116
+ * Encerramento seguro da sessão (`sign_out`)
117
+
118
+ ---
119
+
120
+ ### Requisitos
121
+
122
+ * Python **3.10+** (recomendado)
123
+ * Acesso ao Tableau Server
124
+ * Personal Access Token ativo no Tableau
125
+
126
+ ---
127
+
128
+ ### Dependências
129
+
130
+ ```bash
131
+ pip install tableauserverclient polars pyarrow
132
+ ```
133
+
134
+ ---
135
+
136
+ ### Uso básico
137
+
138
+ ```python
139
+ from maxsciencelib.leitura_tableau import leitura_tableau
140
+
141
+ df = leitura_tableau(
142
+ nome_token="meu_token_tableau",
143
+ token_acesso="XXXXXXXXXXXXXXXXXXXXXXXX",
144
+ view_id="abcd1234-efgh-5678"
145
+ )
146
+
147
+ df.head()
148
+ ```
149
+
150
+ ---
151
+
152
+ ### Retorno
153
+
154
+ O retorno da função será um objeto:
155
+
156
+ ```python
157
+ polars.DataFrame
158
+ ```
159
+
160
+ ---
161
+
162
+ ### Parâmetros
163
+
164
+ | Parâmetro | Tipo | Descrição |
165
+ | -------------- | ----- | --------------------------------------------------- |
166
+ | `nome_token` | `str` | Nome do Personal Access Token cadastrado no Tableau |
167
+ | `token_acesso` | `str` | Token de acesso pessoal do Tableau |
168
+ | `view_id` | `str` | Identificador da view no Tableau Server |
169
+
170
+
171
+
172
+ ## Licença
173
+
174
+ The MIT License (MIT)
175
+
176
+ ## Autores
177
+
178
+ Daniel Antunes Cordeiros
@@ -0,0 +1,8 @@
1
+ maxsciencelib/__init__.py,sha256=HfJvK0jrb39Ffvn7Ec5e6mD2Swd_R03jpmQSC27Cskc,22
2
+ maxsciencelib/leitura.py,sha256=Mr06_eK98A9ext7pXeRt3RrnuF1VBCGUjMJ_Xs7f-bU,3310
3
+ maxsciencelib-0.0.5.dist-info/licenses/LICENCE,sha256=Z5CpyxPhHkk2b1S2ujxWq0lod5yZrU0umM5yQCSmVac,1112
4
+ tests/teste.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ maxsciencelib-0.0.5.dist-info/METADATA,sha256=NNKc0zQUvogWhdWp8nh4ercNCPxvWopnIWe-7PSbUvc,4375
6
+ maxsciencelib-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ maxsciencelib-0.0.5.dist-info/top_level.txt,sha256=H6bvY4js2feOB4Ar9q_kingsRlv4zr0mKv9gF2UAdA0,20
8
+ maxsciencelib-0.0.5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) [2026] [Daniel Antunes Cordeiro]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ maxsciencelib
2
+ tests
tests/teste.py ADDED
File without changes