import swat

conn = swat.CAS(host, port, username, password)

"""
Explanation: Exporting Data from CAS using Python
While the save action can export data to many formats and data sources, there are also ways of easily converting CAS table data to formats on the client as well.  Keep in mind though that while you can export large data sets on the server, you may not want to attempt to bring tens of gigabytes of data down to the client using these methods.
While you can always use the fetch action to get the data from a CAS table, you might just want to export the data to a file.  To make this easier, the CASTable objects support the same to_XXX methods as Pandas DataFrames.  This includes to_csv, to_dict, to_excel, to_html, and others.  Behind the scenes, the fetch action is called and the resulting DataFrame is exported to the file corresponding to the export method used.  Let's look at some examples.
First we need a connection to the server.
End of explanation
"""


tbl = conn.read_csv('https://raw.githubusercontent.com/sassoftware/sas-viya-programming/master/data/cars.csv')
tbl

tbl.head()

"""
Explanation: For purposes of this example, we will load some data into the server to work with.  You may already have tables in your server that you can use.
End of explanation
"""


print(tbl.to_csv())

print(tbl.to_html())

print(tbl.to_latex())

"""
Explanation: Now that we have a CASTable object to work with, we can export the data from the CAS table that it references to a local file.  We'll start with CSV.  The to_csv method will return a string of CSV data if you don't specify a filename.  We'll do it that way in the following code.
End of explanation
"""


conn.close()

"""
Explanation: There are many other to_XXX methods on the CASTable object, each of which corresponds to the same to_XXX method on Pandas DataFrames.  The CASTable methods take the same arguments as the DataFrame counterparts, so you can read the Pandas documentation for more information.
End of explanation
"""


