sanmar_sdk.ftp.readers¶
Streaming SanMar’s delimited data files into records, one row at a time.
SanMar’s files are large (the extended product file runs to hundreds of thousands of rows), so nothing here reads a whole file into memory: every reader is a generator over the lines of an open text stream.
Column names are matched after normalizing them, because SanMar’s spelling drifts between
files and guide revisions: STYLE#, BACK_MODEL _IMAGE_URL, CATALOG.COLOR and
Whse_ No become style#, back_model_image_url, catalog_color and whse_no.
Records declare their columns by those normalized names.
Attributes¶
Functions¶
|
Normalize a column name for matching: lowercase, with runs of punctuation as |
|
Open a path for reading, or pass an already-open stream through untouched. |
|
Yield one record per row of a delimited SanMar file. |
Module Contents¶
- sanmar_sdk.ftp.readers.Source[source]¶
A file to read, as a path on disk or a text stream that is already open.
- sanmar_sdk.ftp.readers.normalize_column(name: str) str[source]¶
Normalize a column name for matching: lowercase, with runs of punctuation as
_.#is kept, because SanMar uses it to mean “number” (STYLE#,SALESORDER#).
- sanmar_sdk.ftp.readers.open_source(source: Source, encoding: str = 'utf-8-sig') collections.abc.Iterator[TextIO][source]¶
Open a path for reading, or pass an already-open stream through untouched.
utf-8-sigreads plain UTF-8 too, and drops the byte-order mark SanMar’s CSV files start with.
- sanmar_sdk.ftp.readers.read_delimited[R: sanmar_sdk.base.Record](source: Source, record: type[R], *, columns: collections.abc.Sequence[str], delimiter: str = ',', encoding: str = 'utf-8-sig') collections.abc.Iterator[R][source]¶
Yield one record per row of a delimited SanMar file.
columnsis the file’s layout, already normalized. When the file starts with a header row, its own column names are used and the order ofcolumnsdoes not matter. When it does not, rows must have exactly as many fields ascolumns.- Raises:
FileFormatError – If the header lacks a column the record requires, a headerless row has the wrong number of fields, or a row does not validate. The error names the line.