Skip to content

API reference

to_qif and write_qif, exported from bankstatementparser_writer_qif, generated from the docstrings by mkdocstrings.

bankstatementparser_writer_qif.writer

Structured Quicken Interchange Format (QIF) Writer.

to_qif(data, account_type='Bank', date_format='%Y-%m-%d')

Serialise bank transactions to a Quicken Interchange Format (QIF) text string.

Parameters:

Name Type Description Default
data Sequence[Transaction] | DataFrame | Sequence[Mapping[str, Any]] | Any

Transactions as DataFrame, Transaction list, or dict records.

required
account_type str

QIF header type (default 'Bank', e.g. 'Bank', 'CCard', 'Cash').

'Bank'
date_format str

Date format string for 'D' fields (default '%Y-%m-%d').

'%Y-%m-%d'

Returns:

Type Description
str

Formatted QIF string.

Source code in bankstatementparser_writer_qif/writer.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def to_qif(
    data: (
        Sequence[Transaction]
        | pd.DataFrame
        | Sequence[Mapping[str, Any]]
        | Any
    ),
    account_type: str = "Bank",
    date_format: str = "%Y-%m-%d",
) -> str:
    """Serialise bank transactions to a Quicken Interchange Format (QIF) text string.

    Args:
        data: Transactions as DataFrame, Transaction list, or dict records.
        account_type: QIF header type (default 'Bank', e.g. 'Bank', 'CCard', 'Cash').
        date_format: Date format string for 'D' fields (default '%Y-%m-%d').

    Returns:
        Formatted QIF string.
    """
    records = _normalize_records(data)
    lines: list[str] = [f"!Type:{account_type}"]
    for rec in records:
        lines.extend(_record_lines(rec, date_format))
    return "\n".join(lines) + "\n"

write_qif(data, destination, account_type='Bank', date_format='%Y-%m-%d')

Write transactions to a QIF file on disk.

Parameters:

Name Type Description Default
data Sequence[Transaction] | DataFrame | Sequence[Mapping[str, Any]] | Any

Transactions as DataFrame, Transaction list, or dict records.

required
destination str | PathLike[str]

Path to write the output QIF file.

required
account_type str

QIF header type (default 'Bank').

'Bank'
date_format str

Date format string for 'D' fields.

'%Y-%m-%d'

Returns:

Type Description
Path

Path object pointing to the written file.

Source code in bankstatementparser_writer_qif/writer.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def write_qif(
    data: (
        Sequence[Transaction]
        | pd.DataFrame
        | Sequence[Mapping[str, Any]]
        | Any
    ),
    destination: str | os.PathLike[str],
    account_type: str = "Bank",
    date_format: str = "%Y-%m-%d",
) -> Path:
    """Write transactions to a QIF file on disk.

    Args:
        data: Transactions as DataFrame, Transaction list, or dict records.
        destination: Path to write the output QIF file.
        account_type: QIF header type (default 'Bank').
        date_format: Date format string for 'D' fields.

    Returns:
        Path object pointing to the written file.
    """
    content = to_qif(data, account_type=account_type, date_format=date_format)
    target = Path(destination)
    target.parent.mkdir(parents=True, exist_ok=True)
    target.write_text(content, encoding="utf-8")
    return target