Skip to main content

Python bindings for odin_palace 1C bank statement parser

Project description

odin_palace_py

Python-библиотека для парсинга банковских выписок в формате 1CClientBankExchange.

Ядро написано на Rust (odin_palace), Python-обёртка построена с помощью PyO3 и Maturin.

Установка

pip install odin_palace_py

Быстрый старт

from odin_palace_py import Statement, parse

# Чтение файла выписки (CP1251 или UTF-8)
with open("statement.txt", "rb") as f:
    data: bytes = f.read()

statement: Statement = parse(data)

print(f"Кодировка: {statement.encoding}")
print(f"Заголовок: {statement.header}")
print(f"Документов: {len(statement.documents)}")
print(f"Счетов: {len(statement.accounts)}")

for doc in statement.documents:
    print(f"  #{doc.doc_number} от {doc.doc_date} на сумму {doc.amount}")
    print(f"    Назначение: {doc.purpose}")
    print(f"    Плательщик: {doc.payee_inn} ({doc.payee})")
    print(f"    Контрагент: {doc.counterparty_inn} ({doc.counterparty})")

Работа со счетами

for number, account in statement.accounts.items():
    print(f"Счёт: {number}")
    for interval in account.intervals:
        print(f"  Период: {interval.date_start} - {interval.date_end}")
        print(f"  Начальный остаток: {interval.start_amount}")
        print(f"  Конечный остаток: {interval.end_amount}")

Обработка ошибок

Библиотека предоставляет иерархию исключений для различных ситуаций:

from odin_palace_py import (
    parse,
    ParseError,
    NotStatementError,
    EmptyInputError,
    UnfinishedError,
    SyntaxError,
)

try:
    statement = parse(data)
except EmptyInputError:
    print("Файл пуст")
except NotStatementError:
    print("Файл не является выпиской 1C")
except UnfinishedError:
    print("Выписка не завершена корректно")
except SyntaxError as e:
    detail = e.detail
    print(f"Синтаксическая ошибка на строке {detail.lineno}: {e}")
except ParseError as e:
    print(f"Ошибка парсинга: {e}")

Объект SyntaxError.detail содержит типизированную информацию об ошибке:

Тип Поля Описание
UnexpectedSection lineno, found, context Неожиданная секция
UnexpectedAttribute lineno, key, value Неожиданный атрибут
UnrecognizedLine lineno, line Нераспознанная строка
MissingField lineno, field, context Отсутствует обязательное поле
AccountParseError lineno, message Ошибка парсинга счёта
DocumentParseError lineno, message Ошибка парсинга документа
HookError lineno, message Ошибка в hook-функции

Hooks

Hooks позволяют модифицировать атрибуты секций перед тем, как парсер создаст из них объекты Document или Account.

Hook вызывается после того, как секция полностью прочитана (парсер встретил маркер КонецДокумента или КонецРасчСчет), но до того, как атрибуты обработаны и добавлены в итоговый Statement. Это значит, что hook получает все накопленные ключ-значение пары секции целиком и может их изменить до финальной обработки.

Порядок вызова:

  1. Парсер читает строки секции, накапливая атрибуты в словарь.
  2. Парсер встречает конец секции (КонецДокумента / КонецРасчСчет).
  3. Вызываются все hooks по порядку, каждый получает собранный словарь атрибутов.
  4. Парсер создаёт Document или Account из (возможно изменённых) атрибутов.
from odin_palace_py import parse, SectionType

def my_hook(
    section_type: SectionType,
    attrs: dict[str, str],
    header: dict[str, str],
) -> None:
    if section_type == SectionType.Document:
        # Подменить назначение платежа
        if "НазначениеПлатежа" in attrs:
            attrs["НазначениеПлатежа"] = attrs["НазначениеПлатежа"].upper()

statement = parse(data, hooks=[my_hook])

Если hook выбросит исключение, парсинг прервётся с SyntaxError, а detail будет содержать объект HookError.

Поддерживаемые версии Python

  • CPython 3.10+
  • PyPy 3.10+

Лицензия

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

odin_palace_py-0.1.1-cp310-cp310-win32.whl (368.8 kB view details)

Uploaded CPython 3.10Windows x86

odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl (689.7 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_i686.whl (717.5 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ i686

odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_armv7l.whl (752.4 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ ARMv7l

odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_aarch64.whl (639.2 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ ARM64

odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl (479.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_s390x.whl (522.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ s390x

odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_ppc64le.whl (514.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ppc64le

odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_aarch64.whl (461.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

odin_palace_py-0.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (475.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARMv7l

odin_palace_py-0.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (501.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.5+ i686

odin_palace_py-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (440.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

odin_palace_py-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl (460.4 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-win32.whl.

File metadata

  • Download URL: odin_palace_py-0.1.1-cp310-cp310-win32.whl
  • Upload date:
  • Size: 368.8 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 1714d916f3ecd2e5bd0033c94b03514e269029dbe2d71c21355388e4ced01ca4
MD5 443cff58330ec7526c36e67309e0b1b6
BLAKE2b-256 41ccc17c6d547fa6fcae3e74a1217d5f88ea2994ff1879d8d9891e9f4f531d7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-win32.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 31ee124a17091c0ef3d57bb8c8b68abe82002d566c5b556c516f5b4a5adf253f
MD5 f6dc39cec5f4d97b782e5a05c9a595c8
BLAKE2b-256 a4be4cc847cdebcfb8444fd52096194100a3f7d8c169ef4f56a32053934ebc62

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e85cc37de6d4eb676d02c67baba50adc8ef0f5e66fc1c786967f0fc77d899404
MD5 268ffb3696a8870d85527e8463326881
BLAKE2b-256 f5da0bccd2735254237d1a75e501b239b46d163ce673bbe189a4e226d4bdbd29

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_i686.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 908173e4edeca0c667f496fe15263194e174ad92d6af61540e0679d7cbb976c8
MD5 1af28517836bf1ee4ab95b151e2aa270
BLAKE2b-256 ae16f6d4967dc13d81767e979feeb4fa2302fbf688ea38401e175ada4af761bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_armv7l.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1d73805b1f332550335f3b1165e83140fff9295a1bc12a9395d2db78ee79ec57
MD5 a3d47ae2a189378895350f3af8280710
BLAKE2b-256 fa40f1df5c29b18a29cfeb882fa17e4b20720951502752e552f76d3312f00de3

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-musllinux_1_2_aarch64.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e9de31662caef28037f22e4a4a4797b632ba02690162df981bb14d2489e93667
MD5 edd7ad65c1590f98fa79f04a0c513a4f
BLAKE2b-256 4c99b47e99e478176a0d21e53a686752951457bb8bead963f534ad5e8c342e30

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_s390x.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_s390x.whl
Algorithm Hash digest
SHA256 0fd90e675c414c930ec99ed2c609d6c2df46485c224b58afed5f00a7248da002
MD5 1d36bb5e1dea55b508ad8a8b146ff370
BLAKE2b-256 5d1c3539f9bb18a5bbe6e8f7ea4b8ddbd6da4aa4f2ba3bb7e056f3954f9c2cf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_s390x.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_ppc64le.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_ppc64le.whl
Algorithm Hash digest
SHA256 25f6fcd37c727597fac6db1912a163c464afb71007eaf8d1711206b75af2c2d8
MD5 c31fda249114fc8c26d21b9a8adb48a3
BLAKE2b-256 8bf40b2cf8318f4ba71b8395c8ae516ec7cb6e878ad878030a16c20161ac3c03

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_ppc64le.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2695c7d24c6278ffd94b2b11d10f4f8a2919b063f04872f0f978ab5cd23504bd
MD5 0a8fdb2c945fa6a08f032c95a982611e
BLAKE2b-256 c77796a240004a03603409dd3596c34dda9bd2f922eb77c774c0e1662bd0c3a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 e882ac4911973c275d942da60d93c424f70b3ca9421b2469cba3ab949daa9122
MD5 c10ce978edae2f6f164f512066c821e9
BLAKE2b-256 bce71097a8bfdaec2df057959ffbf84a16046164cb87dd521147ae3b690268a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 9b8999d22a4366dee546c6aed9e82d680189109025640b125a709e79f50ecbb3
MD5 7c4cb3669f051595b10876b4400aec30
BLAKE2b-256 ea9eb4285fc9f35c5bc9258595c6494f992c400d1495b6d2b651d4ccf1ea813c

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26e748ad10b3ccb060d191b367de81126570c8fc468959cdf7aa863d56639f20
MD5 45fa47e3383c426449ad674cf02d1994
BLAKE2b-256 1317a140c8179dc50b7866ec0b5aa5d5c8ee37b2e9dbff88289ebc81bba6a191

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odin_palace_py-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for odin_palace_py-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4e1479124956828b845bc07af8835c0dcdded070e65d33c85dc927eee909e97a
MD5 1dc022f0f0d9141483a252f9d4471668
BLAKE2b-256 a04f1c4626070a14b62f057ff998a9a6e121f8687ec46b19f88a482a63b7ea5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_palace_py-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl:

Publisher: release-please.yml on tochka-public/odin_palace_py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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