Skip to main content

Receipt Scanner

Write applications to charge money to your friends after you paid the whole bill by easily parsing the receipt 💸

PyPI - Version Linters

Why would I use Receipt Scanner

We've all been there: the dinner ended and the bill arrived at the table. Everyone is looking at you to pay for the bill. "I will pay you back immediately", they say. "Just send a picture of the receipt I will transfer you the money". Idiots. We all know most of them will have forgotten about the damn receipt picture as soon as they get into their cars. Now you can take matters into your own hands. Using this library, you can write an application that parses and classifies items from the receipt, and then charges money to your friends automagically. No more waiting for them to calculate the amount they owe you "as soon as they have a minute".

Installation

Install using pip!

pip install receipt-scanner

Usage

As a package

After installation, you can import the scan method from the library. Just pass the image location (it can be a local path or a URL), an optional regular expression to filter the parsed text and the optional debug parameter:

import re
from receipt_scanner import scan

expression = re.compile("([0-9]+\.[0-9]+)")
scanned_text_lines = scan(
    "path/to/some/image.jpg",
    regular_expression=expression,
    debug=True,
)

The scan method returns a list of strings for each text line that the regular expression matched. If no regular expression gets passed, every parsed text line will be returned.

As a CLI

You can also use receipt-scanner as a CLI! Once installed, the scanner command will be available. Here is a sample usage:

scanner --image path/to/some/image.jpg --expression "([0-9]+\.[0-9]+)" --debug

Specifying allowed characters

By default, the library will use for the following characters:

DEFAULT_ALLOWED_CHARACTERS = (
    "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz1234567890\ "
)

Notice that the last "\ " represents the space character.

You can pass a set of allowed characters to the engine, either by using the --characters flag when using the CLI or by passing the allowed_characters attribute to the scan method of the library.

Debugging

The debug flag will show logs of every step, and will freeze each image manipulation step to show the result of said manipulation. This can be useful to understand why the scan command might be returning an empty list, for example (you might find that the image has poor contrast and that the contour of the receipt is not being correctly mapped).

Developing

Requirements

Steps

Clone the repository:

git clone https://github.com/daleal/receipt-scanner.git

cd receipt-scanner

Then, recreate the environment:

make build-env

Once the package is installed for development (poetry install), you can use the CLI from the virtualenv.

Aknowledgements

Most of the code from this project was adapted from StackOverflow answers to questions about contour-finding, denoising and stuff like that. I also used code from several guides from the internet for utilities such as transforming a contour to a rect. Without those answers, most of this library would have been impossible for me to write. Thanks for the awesome information! 💖

Release files for receipt-scanner 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for receipt-scanner 0.3.2
File Size Uploaded
receipt-scanner-0.3.2.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for receipt-scanner 0.3.2
File Interpreter ABI Platform
receipt_scanner-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / receipt-scanner-0.3.2.tar.gz

Download URL receipt-scanner-0.3.2.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
46412f1e5335f2e0b59e0419c3c9196acd215c30eb4067c240d213a7c11d181d
BLAKE2b-256 checksum
How to use checksums
80a8ffc1de751c4199901ba66ce4a0dcbc2c30388284ddc829a9e78497c56f3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / receipt_scanner-0.3.2-py3-none-any.whl

Download URL receipt_scanner-0.3.2-py3-none-any.whl
Size 18.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e18a80f7081792c0fa813dbe8381764ef0713f261f3b66e0c5a1f50af720ea6c
BLAKE2b-256 checksum
How to use checksums
ac5b0924c10b28ca354ba8e6a445ee6d264aa32a6e144de76ee22ec448523051
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page