beansoup.importers package¶
Submodules¶
beansoup.importers.amex module¶
Importers for American Express statements.
-
class
beansoup.importers.amex.
PdfFilingImporter
(account, basename=None, first_day=1, filename_regexp=None)[source]¶ Bases:
beansoup.importers.filing.Importer
A filing importer for American Express PDF monthly statements.
-
filename_regexp
= '^Statement_(?P<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (?P<year>\\d{4})\\.pdf$'¶
-
beansoup.importers.csv module¶
Utilities to implement CSV importers.
-
class
beansoup.importers.csv.
Importer
(account, currency='CAD', basename=None, first_day=None, filename_regexp=None, account_types=None)[source]¶ Bases:
beancount.ingest.importer.ImporterProtocol
An importer base class for CSV bank and credit card statements.
Unfortunately, CSV files often do not contain any information to easily identify the account; for this reason, this importer relies on the name of the file to associate it to a particular account.
Derived classes need to implement the ‘parse’ method.
See beansoup.importers.td.Importer for a full example of how to derive a concrete importer from this class.
-
parse
(file)[source]¶ Parse the CSV file.
Derived classes must implement this method to parse their CSV files.
Consider using the helper function ‘beansoup.importers.csv.parse’ to implement your custom CSV parser.
Parameters: file – A cache.FileMemo object. Returns: A list of Row objects; one object per row. The order of the parsed rows is irrelevant; they will be sorted in ascending chronological order in a way that agrees with the balance values associated to each row. It that is not possible, the balance values will be ignored and the importer will be unable to extract balance directive, but will otherwise work as expected.
-
-
class
beansoup.importers.csv.
Row
(lineno, date, description, amount, balance)¶ Bases:
tuple
-
__getnewargs__
()¶ Return self as a plain tuple. Used by copy and pickle.
-
__getstate__
()¶ Exclude the OrderedDict from pickling
-
static
__new__
(_cls, lineno, date, description, amount, balance)¶ Create new instance of Row(lineno, date, description, amount, balance)
-
__repr__
()¶ Return a nicely formatted representation string
-
amount
¶ Alias for field number 3
-
balance
¶ Alias for field number 4
-
date
¶ Alias for field number 1
-
description
¶ Alias for field number 2
-
lineno
¶ Alias for field number 0
-
-
beansoup.importers.csv.
parse
(file, dialect, parse_row)[source]¶ Parse a CSV file.
This utility function makes it easy to parse a CSV file format for bank or credit card accounts.
It takes advantage of the ability to cache the file contents, but it does not attempt to cache the parsed result. Be careful when you consider caching the result of your parser in a cache.FileMemo object; often your row parser will adjust the sign of the row balance according to the sign of the account associated with the importer using the parser; this means that CSV importers for accounts of opposite signs should not share the parsed results!
Parameters: - file – A cache.FileMemo object; the CSV file to be parsed.
- dialect – The name of a registered CSV dialect to use for parsing.
- parse_row – A function taking a row (a list of values) and its line number in the input file and returning a Row object.
Returns: A list of Row objects in the same order as encountered in the CSV file.
-
beansoup.importers.csv.
sort_rows
(rows)[source]¶ Sort the rows of a CSV file.
This function can sort the rows of a CSV file in ascending chronological order such that the balance values of each row match the sequence of transactions.
Parameters: rows – A list of objects with a lineno, date, amount, and balance attributes. - Returns
- A pair with a sorted list of rows and an error. The error is None if the function could find an ordering agreeing with the balance values of its rows; otherwise, it is the line number in the CSV file corresponding to the first row not agreeing with its balance value.
beansoup.importers.filing module¶
A file-only importer.
-
class
beansoup.importers.filing.
Importer
(account, basename=None, first_day=1, filename_regexp=None)[source]¶ Bases:
beancount.ingest.importer.ImporterProtocol
A document-filing class for monthly files; it does not import anything.
This importer only supports bean-identify and bean-file. It does not extract any transactions; in fact, it does not even open the file. It uses a regular expression to match a filename to an account and to a date (interpreted as the last day of a billing period).
beansoup.importers.mixins module¶
Mixins for importer classes.
beansoup.importers.td module¶
Importers for TD Canada Trust.
-
class
beansoup.importers.td.
Importer
(account, currency='CAD', basename=None, first_day=None, filename_regexp=None, account_types=None)[source]¶ Bases:
beansoup.importers.csv.Importer
An importer for TD Canada Trust CSV statements.