Skip to main content

A Python library designed to parse bank operations from PDF statements

Project description

Welcome to the statement-reader

About

Welcome to the official documentation for statement-reader — a Python library designed to help you extract and structure data from bank PDF statements.

Banking operations are often provided in PDF format, which is great for human readability but not ideal for further processing by computers. This library solves that problem by parsing unstructured PDF text into structured Python objects that can be easily analyzed, stored, or visualized.


Basic usage

import psycopg2
from statement_reader.parsers import SberParser
from statement_reader.models import Operation
from pypdf import PdfReader

data: list[Operation] = []

reader = PdfReader("example.pdf")
for page in reader.pages:
    raw_str = page.extract_text()
    data.extend(SberParser.parse_lines(str_=raw_str))

conn = psycopg2.connect(dsn="postgres://postgres:secretpassword@localhost:15432/postgres")
with conn.cursor() as c:
    c.execute("DELETE FROM public.stats")
    for operation in data:
        c.execute(
            f"""
                INSERT INTO public.stats (date_, time, category, income, remains, sum, weekday)
                VALUES (%(date)s, %(time)s, %(category)s, %(is_income)s, %(remains)s, %(sum)s, %(weekday)s);
            """, operation.model_dump()
        )
conn.commit()

Why Use statement-reader?

  • Extracts key operation fields: date, time, category, amount, balance, and more.
  • Supports income/expense classification based on the transaction pattern.
  • Automatically cleans up non-breaking spaces and commas for correct numeric parsing.
  • Returns structured Python objects for easy integration with other tools and libraries.
  • Designed for Sberbank statement lines, but extensible to other formats.

Getting Started

To get started, install the package:

pip install statement-reader

Usage

Use it to parse a line from a Sberbank statement:

from statement_reader.parsers import SberParser
line = "12.03.2024 14:22 456789 КАФЕ +100.00 12345.67" 
operation = SberParser.parse_main_line(line)
print(operation.model_dump())
#> {
#>  'date': '2024-03-12',
#>  'time': '14:22',
#>  'category': 'КАФЕ',
#>  'sum': 100.0,
#>  'remains': 12345.67,
#>  'is_income': True,
#>  'weekday': 2
#> }

API Reference

For full details about classes, methods, and parameters, check out the API reference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statement_reader-0.2.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statement_reader-0.2.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file statement_reader-0.2.2.tar.gz.

File metadata

  • Download URL: statement_reader-0.2.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.4 CPython/3.12.11 Linux/6.14.0-24-generic

File hashes

Hashes for statement_reader-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c9c4698b690c7ee7b3fc1abb5612db89cb9300e2264d1d354ccc79028fb09978
MD5 3603fedb5781d0e37a53ccbba87ac3ab
BLAKE2b-256 fa8be31cd6b40fc986a5a263cccdd2d497b4d6f977c0df7b3928cb31e3276818

See more details on using hashes here.

File details

Details for the file statement_reader-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: statement_reader-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.4 CPython/3.12.11 Linux/6.14.0-24-generic

File hashes

Hashes for statement_reader-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a8c8d5aa5b3a4dc748f4bbb04bb80137c0d5e27ced82b505a8a356fcd2745499
MD5 b292b12ff31547d8dc73d8b34e048d55
BLAKE2b-256 68b3b931560f652c001e1e457ef333eb12bc894af52bf34e410156e2ecd95d16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page