cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to call python script in SnapLogic

sanam
New Contributor

Hi Team,

I need to call below sample python script from snaplogic.
or is there a way to call .py file in snaplogic

import pandas as pd
################Can be snap logic pipeline###############333333
import pyodbc
conn = pyodbc.connect(โ€˜DRIVER={ODBC Driver 13 for SQL Server};
SERVER=ps-sql; database=test; trusted_connection=yesโ€™)
sql = โ€˜โ€™โ€™
select * from temp
โ€˜โ€™โ€™
df = pd.read_sql(sql, conn)
######################################################33
#######################Feed SQL into python######################3

import pandas as pd
longform = pd.DataFrame(columns=[โ€˜assets__cโ€™, โ€˜idโ€™])
for idx, songs, name in df.itertuples():
name_words = (i.lower() for i in name.split())
longform = longform.append(
[{โ€˜assets__cโ€™: nw, โ€˜idโ€™: songs} for nw in name_words],
ignore_index=True
)
longform[โ€˜refreshdate_unpackโ€™] = pd.to_datetime(โ€˜todayโ€™)

longform
##############Write longform into a sql table######################

8 REPLIES 8

Hi @rsramkoski

Even if he goes with RPE and Pandas, โ€ฆ then what about pyodbc? Is it supported in RPE?

If you check the py-libs:
https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/615415845/Remote+Python+Executor+RPE+Insta...

Not only pyodbc, but all the other python connectors to the databases - how are they supported via RPE?

/Igor

@igormicev We do not restrict which third-party Python libraries work in the RPE snap. Custom scripts like this though would be outside the scope of our Support team, meaning they need to be supported by the team that develops them. What is the driving factor to use pyodbc or another Python library to connect to SQL Server instead of the SQL Server snap pack or JDBC snap pack?

Hi,

Thanks for the reply I have got RPS installed but I am not able to use external lib

import pyodbc
from pylab import title, figure, xlabel, ylabel, xticks, bar, legend, axis, savefig
from IPython.display import Math

Python script error: ModuleNotFoundError(โ€œNo module named โ€˜pylabโ€™โ€,)
I need to conncet to SQL and read the data for further processing
what is required to use them in the remote python script?

igormicev
Contributor

@rsramkoski, thanks for your reply, it answered my question.
I donโ€™t know whatโ€™s the driving factor to use third-party libs instead of some of the snaps. I guess the OP would liked to make/try some data wrangling with DataFrame.