Automatically sort and archive PDF bills and statements
Project description
classify_bills
[Almost] automatically sort and archive PDF bills and statements.
I get tons of electronic statements each month: from bank statements to credit cards statements to updated insurance policy documents. I store all of them - they don't take much space and you never know when you need to use one of them (I did have a case quite recently, where a receipt from a bank issued 18 years ago had made all the difference, but that's a story for some other day).
One problem with so many receipts is storing them in a way that helps finding things fast (or even finding things at all). Renaming each file by hand sticking to some uniform convention and shuffling those files around gets mind numbingly boring pretty soon.
This is where classify_bills
script comes handy. It goes over all
newly downloaded bills and does a couple of things:
- It tries to figure out what account each document belongs to.
- It then figures out what date this document should be associated with.
- Finally, it names the document according to the set pattern and places it in the right directory.
What classify_bills
is not
It is not a jack of all trades. It will not download your statements for you (which is a much more complex task given different websites hosting those documents). Neither will it OCR those documents that don't come with text embedded (some places give you a PDF which has no text at all).
It is also not really intelligent. At its core, it is driven by a list of regular expressions.
Still, given the number of bills I get monthly, over the last couple years, it has saved me probably hours of menial, incredibly boring work, so I do consider it a win.
Installation
Install using pip
:
pip install classify_bills
Once installed, classify_bills
should be available in your path.
When using the source code directly or from GitHub, use
run_classify_bills
shell driver that will invoke the Python code
properly.
Currently, the classify_bills
has the following external
dependencies:
- Python 3.x
pdftotext
program (usually comes as part ofpoppler
package.)
Configuration
classify_bills
is configured via a set of XML files, where each file
defines a setup for a specific bill type. Those files should be placed
in a configuration directory, which could be specified one of the
following ways:
- Via
-c
command line option. - Via an environment variable
$CLASSIFY_BILLS_CONFIG_DIRECTORY
- Using a default location
~/.classify_bills.conf.d
Each file defines patterns that might be present in the bill's text in
order to be considered for this account. A pattern to match bill date
also must be specified (and must be matched) as well as a pattern to
extract the date (via strptime()
).
The package directory classify_bills.config.examples
contains
several examples. In particular, see 0-Example.xml
in that
directory, which describes all aspects of configuration.
Lastly, color in the output can be disabled by setting
$CLASSIFY_BILLS_DISABLE_COLOR
environment variable.
Creating new configuration files
In general, a process of adding support for a new kind of bill works the following way:
- Use
pdftotext
to examine text output of a couple bills for a given account to determine the following:- Patterns in the text that could be used to uniquely identify this kind of bill (name of a bank or service provider, URLs, etc). It's beter to have several specific patterns to allow future disambiguation between multiple accounts from the same provider (e.g. separate banking and investment bills from the same bank).
- Pattern that could be used to infer the date this bill should be associated with.
- Format of that date.
- Create a new XML file (use
0-Example.xml
as a boilerplate).
This process is unfortunately not easy to automate so it has to be done manually and it is a pain. However, it only has to be done once per each account (that is, until the provider decides to change the format of the bill thus breaking the patterns, but it also doesn't happen often).
Using classify_bills
Running classify_bills
is fairly simple. You can pass either
individual PDF files or directories as command-line arguments. By
default, it runs in dry-run mode, not making any changes. To actually
perform all actions, run it with -f
flag.
Files that have been successfully detected are moved to the hierarchy
under the output directory (which is specified either with -o
flag
or via an environment variable $CLASSIFY_BILLS_OUTPUT_DIRECTORY
. The
script will never overwrite any existing document in the destination
directory (unless it is forced to via -w
flag).
Future work
Currently, the most painful aspect of using the tool is manual configuration of patterns for each bill type. There are several ideas on how to try to make it easier: from finding and parsing all dates in the bill to using neural networks to infer those facts from the bill. This might be an interesting direction for future work.
Contributing
You are welcome to contribute to this project either by submitting bill configuration for different institutions or by improving the code and adding features. :-)
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 Distributions
Built Distribution
File details
Details for the file classify_bills-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: classify_bills-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277cb5e99ab5bfd907436af40670c56f4827097d6af6beef059aa0f0f25e2001 |
|
MD5 | fd10162200d1a43ddbeca70d59565caa |
|
BLAKE2b-256 | cbe5b31a75811fa8fd120c9a585a3b4e267bd9032805c8d66220001333f7f78a |