A lightweight SFTP reader built on top of paramiko and polars. Connects to remote servers and pulls files down as strings, Polars DataFrames, or raw text.
pip install paramiko polars chardetThen drop cornflex/ into your project.
from cornflex import SFTPReaderreader = SFTPReader(
hostname="sftp.example.com",
username="myuser",
password="mypassword",
)reader = SFTPReader(
hostname="sftp.example.com",
username="myuser",
pem_file="/path/to/key.pem",
)Lists files in a remote directory. Supports glob-style patterns.
reader.get_files(remote_path="/data", file_pattern="*.csv")
# ["orders_2024.csv", "users_2024.csv"]Fetches a CSV and returns it as a Polars DataFrame.
reader.connect()
df = reader.get_csv_file("orders.csv", remote_path="/data")
# Override column names (useful when file has no header)
df = reader.get_csv_file("orders.csv", remote_path="/data", column_names=["id", "amount", "date"])
reader.close()Fetches an XML file and returns it as a string.
reader.connect()
xml = reader.get_xml_file_to_string("feed.xml", remote_path="/exports")
reader.close()Fetches any file as a string. Auto-detects encoding via chardet if not specified.
reader.connect()
content = reader.file_to_string("report.txt", remote_path="/reports")
# Force encoding
content = reader.file_to_string("report.txt", encoding="latin-1")
reader.close()get_files()handles connect/close internally.- For all other methods, call
connect()before andclose()after. - Either
passwordorpem_filemust be provided — not both, not neither. get_csv_fileassumes UTF-8. Usefile_to_stringfor other encodings.
| Package | Purpose |
|---|---|
paramiko |
SSH/SFTP connection |
polars |
DataFrame output |
chardet |
Encoding detection |