pandas-plots 0.0.3__py3-none-any.whl → 0.3.1__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.
pandas_plots/sql.py ADDED
@@ -0,0 +1,75 @@
1
+ from typing import Literal
2
+
3
+ from sqlalchemy import create_engine, text
4
+ from sqlalchemy_utils import create_database, database_exists
5
+
6
+
7
+ def connect_sql(
8
+ db: str,
9
+ host: str = '',
10
+ user: str = '',
11
+ pw: str = '',
12
+ dbms: Literal['mssql', 'sqlite','postgres'] = 'mssql',
13
+ ensure_db_exists: bool = False,
14
+ ) -> object:
15
+ """
16
+ Connects to any SQL database based on the given parameters.
17
+
18
+ Args:
19
+ db (str): The name of the database / sqlite-file.
20
+ host (str, optional): The host name or IP address of the database server. Defaults to an empty string.
21
+ user (str, optional): The username for authentication. Defaults to an empty string.
22
+ pw (str, optional): The password for authentication. Defaults to an empty string.
23
+ dbms (Literal['mssql', 'sqlite','postgres'], optional): The type of database management system. Defaults to 'mssql'.
24
+ ensure_db_exists (bool, optional): Specifies whether to create the database if it does not exist. Defaults to False.
25
+
26
+ Returns:
27
+ Connection: The connection object for the established database connection.
28
+
29
+ Remarks:
30
+ - postgres
31
+ - psycopg2-binary must be installed
32
+ - example:
33
+ con = my_connect_to_any_sql(
34
+ host='<instance>.postgres.database.azure.com',
35
+ db='eteste',
36
+ user='<user>n@<instance>',
37
+ pw='<password>',
38
+ dbms='postgres',
39
+ ensure_db_exists=False
40
+ )
41
+ - mssql
42
+ - sqlalchemy nust be <v2 to write -> sql
43
+
44
+ """
45
+
46
+ if dbms == 'mssql':
47
+ url = f'mssql://{user}:{pw}@{host}/{db}?driver=ODBC Driver 17 for SQL Server'
48
+ elif dbms == 'sqlite':
49
+ url = f'sqlite:///{db}'
50
+ elif dbms == 'postgres':
51
+ url = f'postgresql+psycopg2://{user}:{pw}@{host}/{db}'
52
+ else:
53
+ print("dbms not supported")
54
+ return None
55
+
56
+ engine = create_engine(
57
+ url, # * leave positional argument unnamed, since it was relabeled between versions..
58
+ connect_args={'connect_timeout': 10},
59
+ )
60
+
61
+ # * ensure db exists
62
+ if ensure_db_exists:
63
+ if not database_exists(engine.url):
64
+ create_database(engine.url)
65
+ print(f'db {db} created')
66
+ else:
67
+ print(f'db {db} exists')
68
+
69
+ # * now connect
70
+ try:
71
+ con=engine.connect()
72
+ except Exception as e:
73
+ print(e)
74
+
75
+ return con
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandas-plots
3
- Version: 0.0.3
3
+ Version: 0.3.1
4
4
  Summary: A collection of helper for pandas n plots
5
5
  Author-email: smeisegeier <dsexterDSDo@googlemail.com>
6
6
  License: Copyright 2024 smeisegeier
@@ -11,10 +11,18 @@ License: Copyright 2024 smeisegeier
11
11
 
12
12
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
13
 
14
- Project-URL: Homepage, https://github.com/smeisegeier/pandas-plots
14
+ Project-URL: homepage, https://github.com/smeisegeier/pandas-plots
15
+ Project-URL: repository, https://github.com/smeisegeier/pandas-plots
15
16
  Keywords: tables,pivot,plotly
16
17
  Classifier: License :: OSI Approved :: MIT License
17
18
  Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Development Status :: 5 - Production/Stable
21
+ Classifier: Development Status :: 3 - Alpha
22
+ Classifier: Environment :: Console
23
+ Classifier: Intended Audience :: Science/Research
24
+ Classifier: Operating System :: OS Independent
25
+ Classifier: Topic :: Scientific/Engineering
18
26
  Requires-Python: >=3.10
19
27
  Description-Content-Type: text/markdown
20
28
  License-File: LICENSE
@@ -22,15 +30,13 @@ Requires-Dist: pandas >=2.0.0
22
30
  Requires-Dist: plotly
23
31
  Requires-Dist: matplotlib
24
32
  Requires-Dist: seaborn
33
+ Requires-Dist: sqlalchemy <2.0.0
25
34
 
26
35
  # pandas-plots
27
36
 
28
- <!-- [![GitHub release](https://img.shields.io/github/release/Naereen/StrapDown.js.svg)](https://GitHub.com/Naereen/StrapDown.js/releases/) -->
29
- <!-- [![GitHub latest commit](https://badgen.net/github/last-commit/Naereen/Strapdown.js)](https://GitHub.com/Naereen/StrapDown.js/commit/) -->
37
+ ![PyPI - Version](https://img.shields.io/pypi/v/pandas-plots) ![GitHub last commit](https://img.shields.io/github/last-commit/smeisegeier/pandas-plots?logo=github) ![GitHub License](https://img.shields.io/github/license/smeisegeier/pandas-plots?logo=github) ![py3.10](https://img.shields.io/badge/python-3.10-blue.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICA8ZGVmcz4KICAgIDxsaW5lYXJHcmFkaWVudCBpZD0icHlZZWxsb3ciIGdyYWRpZW50VHJhbnNmb3JtPSJyb3RhdGUoNDUpIj4KICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iI2ZlNSIgb2Zmc2V0PSIwLjYiLz4KICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iI2RhMSIgb2Zmc2V0PSIxIi8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJweUJsdWUiIGdyYWRpZW50VHJhbnNmb3JtPSJyb3RhdGUoNDUpIj4KICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iIzY5ZiIgb2Zmc2V0PSIwLjQiLz4K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c3RvcC1jb2xvcj0iI2RhMSIgb2Zmc2V0PSIxIi8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJweUJsdWUiIGdyYWRpZW50VHJhbnNmb3JtPSJyb3RhdGUoNDUpIj4KICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iIzY5ZiIgb2Zmc2V0PSIwLjQiLz4KICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iIzQ2OCIgb2Zmc2V0PSIxIi8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogIDwvZGVmcz4KCiAgPHBhdGggZD0iTTI3LDE2YzAtNyw5LTEzLDI0LTEzYzE1LDAsMjMsNiwyMywxM2wwLDIyYzAsNy01LDEyLTExLDEybC0yNCwwYy04LDAtMTQsNi0xNCwxNWwwLDEwbC05LDBjLTgsMC0xMy05LTEzLTI0YzAtMTQsNS0yMywxMy0yM2wzNSwwbDAtM2wtMjQsMGwwLTlsMCwweiBNODgsNTB2MSIgZmlsbD0idXJsKCNweUJsdWUpIi8+CiAgPHBhdGggZD0iTTc0LDg3YzAsNy04LDEzLTIzLDEzYy0xNSwwLTI0LTYtMjQtMTNsMC0yMmMwLTcsNi0xMiwxMi0xMmwyNCwwYzgsMCwxNC03LDE0LTE1bDAtMTBsOSwwYzcsMCwxMyw5LDEzLDIzYzAsMTUtNiwyNC0xMywyNGwtMzUsMGwwLDNsMjMsMGwwLDlsMCwweiBNMTQwLDUwdjEiIGZpbGw9InVybCgjcHlZZWxsb3cpIi8+CgogIDxjaXJjbGUgcj0iNCIgY3g9IjY0IiBjeT0iODgiIGZpbGw9IiNGRkYiLz4KICA8Y2lyY2xlIHI9IjQiIGN4PSIzNyIgY3k9IjE1IiBmaWxsPSIjRkZGIi8+Cjwvc3ZnPgo=)
32
-
33
- ## quickstart
39
+ ## usage
34
40
 
35
41
  install / update package
36
42
 
@@ -44,7 +50,7 @@ include in python
44
50
  from pandas_plots import tbl, viz
45
51
  ```
46
52
 
47
- example
53
+ ## example
48
54
 
49
55
  ```python
50
56
  # load sample dataset from seaborn
@@ -53,7 +59,8 @@ df = sb.load_dataset('taxis')
53
59
 
54
60
  viz.plot_box(df['fare'], height=400, violin=True)
55
61
  ```
56
- ![plot_box](img/2024-02-13-00-40-27.png)
62
+
63
+ ![plot_box](https://github.com/smeisegeier/pandas-plots/blob/main/img/2024-02-13-00-40-27.png?raw=true)
57
64
 
58
65
  ## why use pandas-plots
59
66
 
@@ -72,4 +79,7 @@ It is subdivided into:
72
79
  - `plot_stacked_bars()` shortcut to stacked bars 😄
73
80
  - `plot_quadrants()` quickly show a 2x2 heatmap
74
81
 
82
+ - `sql` is added as convienient wrapper for fetching data from sql databases
83
+ - `connect_sql` get data from `['mssql', 'sqlite','postgres']`
84
+
75
85
  ## dependencies
@@ -0,0 +1,9 @@
1
+ pandas_plots/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ pandas_plots/sql.py,sha256=SHrmwhmzq0QYygvaoKwv7neiwf_Rv87VmdUkADYPdR8,2485
3
+ pandas_plots/tbl.py,sha256=7_o-Mu2nrniZd25zAtb_7IUdi7ZUnjcn9OFpBwFcVno,11500
4
+ pandas_plots/viz.py,sha256=eCDth3aFSU0_8Cj5Tax-FWM9TmPrmmNEiFuoVOB63ss,23207
5
+ pandas_plots-0.3.1.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
6
+ pandas_plots-0.3.1.dist-info/METADATA,sha256=VC7bKNzOVxg0GyvBSAyZm0gfKZB8g0BdzrWpEhFvZL0,4983
7
+ pandas_plots-0.3.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
8
+ pandas_plots-0.3.1.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
9
+ pandas_plots-0.3.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- pandas_plots/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- pandas_plots/tbl.py,sha256=7_o-Mu2nrniZd25zAtb_7IUdi7ZUnjcn9OFpBwFcVno,11500
3
- pandas_plots/viz.py,sha256=eCDth3aFSU0_8Cj5Tax-FWM9TmPrmmNEiFuoVOB63ss,23207
4
- pandas_plots-0.0.3.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
5
- pandas_plots-0.0.3.dist-info/METADATA,sha256=CxfXjnDBAnALI1yDqMIi9SRh6hfOfJPWGmw7e2p4bt0,4379
6
- pandas_plots-0.0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
7
- pandas_plots-0.0.3.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
8
- pandas_plots-0.0.3.dist-info/RECORD,,