main #3

Merged
steve merged 17 commits from main into master 2 weeks ago

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.

@ -4,34 +4,40 @@ This project implements an abstraction of objects that can have access to a vari
# Why Use Data-Transport ? # Why Use Data-Transport ?
Mostly data scientists that don't really care about the underlying database and would like a simple and consistent way to read/write and move data are well served. Additionally we implemented lightweight Extract Transform Loading API and command line (CLI) tool. Finally it is possible to add pre/post processing pipeline functions to read/write Data transport is a simple framework that enables read/write to multiple databases or technologies that can hold data. In using **data-transport**, you are able to:
1. Familiarity with **pandas data-frames**
2. Connectivity **drivers** are included
3. Reading/Writing data from various sources
4. Useful for data migrations or **ETL**
- Enjoy the simplicity of **data-transport** because it leverages SQLAlchemy & Pandas data-frames.
- Share notebooks and code without having to disclosing database credentials.
- Seamlessly and consistently access to multiple database technologies at no cost
- No need to worry about accidental writes to a database leading to inconsistent data
- Implement consistent pre and post processing as a pipeline i.e aggregation of functions
- **data-transport** is open-source under MIT License https://github.com/lnyemba/data-transport
## Installation ## Installation
Within the virtual environment perform the following : Within the virtual environment perform the following, the options for installation are:
pip install git+https://github.com/lnyemba/data-transport.git **sql** - by default postgresql, mysql, sqlserver, sqlite3+, duckdb
## Features pip install data-transport[cloud,nosql,other,all]git+https://github.com/lnyemba/data-transport.git
- read/write from over a dozen databases Options to install components in square brackets, these components are
- run ETL jobs seamlessly
- scales and integrates into shared environments like apache zeppelin; jupyterhub; SageMaker; ... **warehouse** - Apache Iceberg, Apache Drill
## What's new **cloud**  - to support nextcloud, s3
Unlike older versions 2.0 and under, we focus on collaborative environments like jupyter-x servers; apache zeppelin: **nosql** - support for mongodb, couchdb
1. Simpler syntax to create reader or writer **other**  - support for files, rabbitmq, http
2. auth-file registry that can be referenced using a label
3. duckdb support
pip install data-transport[nosql,cloud,warehouse,all]@git+https://github.com/lnyemba/data-transport.git
## Additional features
- In addition to read/write, there is support for functions for pre/post processing
- CLI interface to add to registry, run ETL
- scales and integrates into shared environments like apache zeppelin; jupyterhub; SageMaker; ...
## Learn More ## Learn More

@ -53,9 +53,9 @@ def wait(jobs):
while jobs : while jobs :
jobs = [thread for thread in jobs if thread.is_alive()] jobs = [thread for thread in jobs if thread.is_alive()]
time.sleep(1) time.sleep(1)
def wait (jobs): # def wait (jobs):
while jobs : # while jobs :
jobs = [pthread for pthread in jobs if pthread.is_alive()] # jobs = [pthread for pthread in jobs if pthread.is_alive()]
@app_e.command(name="run") @app_e.command(name="run")
def apply (path:Annotated[str,typer.Argument(help="path of the configuration file")], def apply (path:Annotated[str,typer.Argument(help="path of the configuration file")],
@ -178,7 +178,17 @@ def register (label:Annotated[str,typer.Argument(help="unique label that will be
_msg = f"""{TIMES_MARK} {e}""" _msg = f"""{TIMES_MARK} {e}"""
print (_msg) print (_msg)
pass @app_r.command(name="list")
def register_list ():
"""
This function will list existing registry entries and basic information {label,vendor}
"""
# print (transport.registry.DATA)
_reg = transport.registry.DATA
_data = [{'label':key,'provider':_reg[key]['provider']} for key in _reg if 'provider' in _reg[key]]
_data = pd.DataFrame(_data)
print (_data)
@app_x.command(name='add') @app_x.command(name='add')
def register_plugs ( def register_plugs (
alias:Annotated[str,typer.Argument(help="unique function name within a file")], alias:Annotated[str,typer.Argument(help="unique function name within a file")],

@ -0,0 +1,2 @@
cd /D "%~dp0"
python transport %1 %2 %3 %4 %5 %6

@ -18,25 +18,17 @@ classifiers = [
] ]
dependencies = [ dependencies = [
"termcolor","sqlalchemy", "aiosqlite","duckdb-engine", "termcolor","sqlalchemy", "aiosqlite","duckdb-engine",
"typer","pandas","numpy","sqlalchemy","pyarrow", "mysql-connector-python","psycopg2-binary","nzpy","pymssql","duckdb-engine","aiosqlite",
"typer","pandas","numpy","sqlalchemy","pyarrow","smart-open",
"plugin-ix@git+https://github.com/lnyemba/plugins-ix" "plugin-ix@git+https://github.com/lnyemba/plugins-ix"
] ]
[project.optional-dependencies] [project.optional-dependencies]
sql = ["mysql-connector-python","psycopg2-binary","nzpy","pymssql","duckdb-engine","aiosqlite"] #sql = ["mysql-connector-python","psycopg2-binary","nzpy","pymssql","duckdb-engine","aiosqlite"]
nosql = ["pymongo","cloudant"] nosql = ["pymongo","cloudant"]
cloud = ["pandas-gbq","google-cloud-bigquery","google-cloud-bigquery-storage", "databricks-sqlalchemy","pyncclient","boto3","boto","botocore"] cloud = ["boto","boto3","botocore","pyncclient","pandas-gbq","google-cloud-bigquery","google-cloud-bigquery-storage", "databricks-sqlalchemy","pyncclient","boto3","boto","botocore"]
warehouse = ["pydrill","pyspark","sqlalchemy_drill"] warehouse = ["pydrill","pyspark","sqlalchemy_drill"]
rabbitmq = ["pika"] other = ["pika","flask-session"]
sqlite = ["aiosqlite"] all = ["pymongo","cloudant","pandas-gbq","google-cloud-bigquery","google-cloud-bigquery-storage", "databricks-sqlalchemy","pyncclient","boto3","boto","botocore","pydrill","pyspark","sqlalchemy_drill", "pika","aiosqlite","boto3","boto","botocore", "pyncclient"]
aws3 = ["boto3","boto","botocore"]
nextcloud = ["pyncclient"]
mongodb = ["pymongo"]
netezza = ["nzpy"]
mysql = ["mysql-connector-python"]
postgresql = ["psycopg2-binary"]
sqlserver = ["pymssql"]
http = ["flask-session"]
all = ["mysql-connector-python","psycopg2-binary","nzpy","pymssql","duckdb-engine","aiosqlite","pymongo","cloudant","pandas-gbq","google-cloud-bigquery","google-cloud-bigquery-storage", "databricks-sqlalchemy","pyncclient","boto3","boto","botocore","pydrill","pyspark","sqlalchemy_drill", "pika","aiosqlite","boto3","boto","botocore", "pyncclient"]
[project.urls] [project.urls]
Homepage = "https://healthcareio.the-phi.com/git/code/transport.git" Homepage = "https://healthcareio.the-phi.com/git/code/transport.git"
@ -47,14 +39,14 @@ Homepage = "https://healthcareio.the-phi.com/git/code/transport.git"
[tool.setuptools] [tool.setuptools]
include-package-data = true include-package-data = true
zip-safe = false zip-safe = false
script-files = ["bin/transport"] script-files = ["bin/transport","bin/transport.cmd"]
[tool.setuptools.packages.find] [tool.setuptools.packages.find]
include = ["info","info.*", "transport", "transport.*"] include = [ "transport", "transport.*"]
[tool.setuptools.dynamic] [tool.setuptools.dynamic]
version = {attr = "info.__version__"} version = {attr = "transport.info.__version__"}
#authors = {attr = "meta.__author__"} #authors = {attr = "transport.__author__"}
# If you have a info.py file, you might also want to include the author dynamically: # If you have a info.py file, you might also want to include the author dynamically:
# [tool.setuptools.dynamic] # [tool.setuptools.dynamic]

@ -18,11 +18,31 @@ Source Code is available under MIT License:
""" """
import numpy as np import numpy as np
from transport import sql, nosql, cloud, other, warehouse #from transport import sql, nosql, cloud, other, warehouse
from transport import sql
try:
from transport import nosql
except Exception as e:
nosql = {}
try:
from transport import cloud
except Exception as e:
cloud = {}
try:
from transport import warehouse
except Exception as e:
warehouse = {}
try:
from transport import other
except Exception as e:
other = {}
import pandas as pd import pandas as pd
import json import json
import os import os
from info import __version__,__author__,__email__,__license__,__app_name__,__whatsnew__,__edition__ from transport.info import __version__,__author__,__email__,__license__,__app_name__,__whatsnew__,__edition__
from transport.iowrapper import IWriter, IReader, IETL from transport.iowrapper import IWriter, IReader, IETL
from transport.plugins import PluginLoader from transport.plugins import PluginLoader
from transport import providers from transport import providers
@ -35,7 +55,7 @@ def init():
global PROVIDERS global PROVIDERS
for _module in [cloud,sql,nosql,other,warehouse] : for _module in [cloud,sql,nosql,other,warehouse] :
for _provider_name in dir(_module) : for _provider_name in dir(_module) :
if _provider_name.startswith('__') or _provider_name == 'common': if _provider_name.startswith('__') or _provider_name == 'common' or type(_module) in [None,str,dict]:
continue continue
PROVIDERS[_provider_name] = {'module':getattr(_module,_provider_name),'type':_module.__name__} PROVIDERS[_provider_name] = {'module':getattr(_module,_provider_name),'type':_module.__name__}
# #

@ -0,0 +1,23 @@
__app_name__ = 'data-transport'
__author__ = 'The Phi Technology'
__version__= '2.2.30'
__email__ = "info@the-phi.com"
__edition__= 'community'
__license__=f"""
Copyright 2010 - 2024, Steve L. Nyemba
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
"""
__whatsnew__=f"""version {__version__},
1. Added support for read/write logs as well as plugins (when applied)
2. Bug fix with duckdb (adding readonly) for readers because there are issues with threads & processes
3. support for streaming data, important to use this with large volumes of data
"""

@ -30,7 +30,11 @@ class Reader (File):
def read(self,**args): def read(self,**args):
_path = self.path if 'path' not in args else args['path'] _path = self.path if 'path' not in args else args['path']
_delimiter = self.delimiter if 'delimiter' not in args else args['delimiter'] _delimiter = self.delimiter if 'delimiter' not in args else args['delimiter']
return pd.read_csv(_path,delimiter=self.delimiter) _df = pd.read_csv(_path,delimiter=self.delimiter)
if 'query' in args :
_query = args['query']
_df = _df.query(_query)
return _df
def stream(self,**args): def stream(self,**args):
raise Exception ("streaming needs to be implemented") raise Exception ("streaming needs to be implemented")
class Writer (File): class Writer (File):

@ -1,6 +1,6 @@
import os import os
import json import json
from info import __version__ from transport.info import __version__
import copy import copy
import transport import transport
import importlib import importlib
@ -49,7 +49,8 @@ def init (email,path=REGISTRY_PATH,override=False,_file=REGISTRY_FILE):
Initializing the registry and will raise an exception in the advent of an issue Initializing the registry and will raise an exception in the advent of an issue
""" """
p = '@' in email p = '@' in email
q = False if '.' not in email else email.split('.')[-1] in ['edu','com','io','ai','org'] #q = False if '.' not in email else email.split('.')[-1] in ['edu','com','io','ai','org']
q = len(email.split('.')[-1]) in [2,3]
if p and q : if p and q :
_config = {"email":email,'version':__version__} _config = {"email":email,'version':__version__}
if not os.path.exists(path): if not os.path.exists(path):

Loading…
Cancel
Save