Skip to main content

Xfina Logo

Xfina (Python Bindings)

Crates.io PyPI npm

Xfina is a blazingly fast library for parsing Indian financial statements (Bank Accounts, Credit Cards, Mutual Funds) and international brokers (IBKR), written in Rust and exposed to Python via PyO3.

It converts raw PDFs, Excel files, and CSVs into structured, ReBIT-compliant JSON dictionaries in milliseconds.

Installation

pip install xfina

Quick Start

The Python bindings expose the exact same parsing functions as the Rust core. To keep the core parsing logic as pure functions without side-effects (like file I/O), the library requires raw bytes to be passed in rather than file paths.

Parsing a Credit Card Statement

import xfina
import os

filename = "icici_cc_statement.xls"

with open(filename, "rb") as f:
    file_bytes = f.read()

result = xfina.parse_icici_cc(
    file_bytes, 
    filename=filename,
    modified_timestamp=int(os.path.getmtime(filename))
)

print(f"Validation Status: {result['validation']['overall']}")

Parsing a Bank Statement (Excel)

import xfina
import os

filename = "hdfc_statement.xls"
modified_ts = int(os.path.getmtime(filename))

# Read the file as raw bytes
with open(filename, "rb") as f:
    file_bytes = f.read()

# Parse it! Providing the filename and modified timestamp helps improve parsing accuracy
result = xfina.parse_hdfc_ba(
    file_bytes, 
    password=None, 
    filename=filename,
    modified_timestamp=modified_ts,
    format="xfina"
)

# The returned dictionary contains both the validation report and the financial data
print(f"Validation Status: {result['validation']['overall']}")
print(f"Account Name: {result['data']['profile']['holders']['holder'][0]['name']}")

Parsing a CAMS Mutual Fund Statement (PDF)

import xfina
import json

with open("cams_cas.pdf", "rb") as f:
    file_bytes = f.read()

# Pass the password to decrypt the PDF
mf_data = xfina.parse_cams(file_bytes, password="PAN1234567")

# It returns a standard Python dictionary. You can easily dump it to JSON:
with open("output.json", "w") as f:
    json.dump(mf_data, f, indent=2)

Parsing an IBKR Statement (CSV)

import xfina

# All parsers now uniformly expect raw bytes, even for CSVs
with open("ibkr_activity.csv", "rb") as f:
    file_bytes = f.read()

result = xfina.parse_ibkr(file_bytes, format="rebit")

Available Parsers

All parsers return a structured Python dictionary that mirrors the ReBIT JSON schema. Each parser accepts an optional format parameter which defaults to "xfina", but can be "rebit" for strict AA schema compliance without our extended data fields.

Category Institution Format Python Function Input Type
Bank Account HDFC .xls parse_hdfc_ba(bytes, **kwargs) bytes
Bank Account ICICI .xls parse_icici_ba(bytes, **kwargs) bytes
Bank Account SBI PDF parse_sbi_ba(bytes, **kwargs) bytes
Bank Account BOB .xls parse_bob_ba(bytes, **kwargs) bytes
Bank Account Axis .xls parse_axis_ba(bytes, **kwargs) bytes
Credit Card HDFC CSV parse_hdfc_cc(bytes, **kwargs) bytes
Credit Card ICICI .xls parse_icici_cc(bytes, **kwargs) bytes
Mutual Funds CAMS PDF parse_cams(bytes, **kwargs) bytes
Intl Stocks IBKR CSV parse_ibkr(bytes, **kwargs) bytes

Note: All Python functions accept the following optional keyword arguments: password, filename, modified_timestamp, and format.

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 Distribution

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

xfina-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

File details

Details for the file xfina-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for xfina-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 67e1ef0a5a42b80c755a98be0f36ef7c280e95f8b16c42aa39ba565154177e19
MD5 cb0e27e56cbd7552adc05b999f08d462
BLAKE2b-256 cb1758f3d93907f4cd32bed63aa2f53ab5a6b63e90acd4409b9439f238fe6b1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for xfina-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on sakthipriyan/xfina

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

Release history Release notifications | RSS feed

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

This release

0.2.1 This release

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Supported by

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