simple sftp reader
Project description
🌽💪 Cornflex 🌽💪
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.
Installation
pip install paramiko polars chardet
Then drop cornflex/ into your project.
Usage
from cornflex import SFTPReader
Connect with password
reader = SFTPReader(
hostname="sftp.example.com",
username="myuser",
password="mypassword",
)
Connect with PEM key
reader = SFTPReader(
hostname="sftp.example.com",
username="myuser",
pem_file="/path/to/key.pem",
)
Methods
get_files(remote_path, file_pattern)
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"]
get_csv_file(file_name, remote_path, column_names)
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()
get_xml_file_to_string(file_name, remote_path)
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()
file_to_string(file_name, remote_path, encoding)
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()
Notes
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.
Dependencies
| Package | Purpose |
|---|---|
paramiko |
SSH/SFTP connection |
polars |
DataFrame output |
chardet |
Encoding detection |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cornflex-1.0.1.tar.gz.
File metadata
- Download URL: cornflex-1.0.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aff1b58a17cca4bc7ef90e6e9a64a676ff5752ff2c740dcac089d34cfd924470
|
|
| MD5 |
79f809fa025fc6b73aa7198ef6593232
|
|
| BLAKE2b-256 |
0a9231d79e5bb78484cd4f700df8346dd3e2514a1726dcf9ba48f634ca9c6d93
|
File details
Details for the file cornflex-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cornflex-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73dbc1f0584e06463948f131b9844c797b6dd06fcb03b72ef85e8e38b69e9522
|
|
| MD5 |
41cbff374fab42755245416712b6c893
|
|
| BLAKE2b-256 |
c562ecde21e06af9ee424d2225c87ed162011dfa5a9d99ec19abac7b8d3ea5fc
|