(CAMS/KFintech/NSDL/CDSL) Consolidated Account Statement (CAS) PDF parser
Project description
CASParser
Parse Consolidated Account Statement (CAS) PDF files generated from CAMS, KFintech, NSDL, and CDSL.
casparser also includes a command line tool with the following analysis tools
summary- print portfolio summary- (BETA)
gains- Print capital gains report (summary and detailed)- with option to generate csv files for ITR in schedule 112A format
Supported inputs
casparser parses original CAS PDFs delivered by the four
recognised issuers:
| Issuer | Variant(s) | Source |
|---|---|---|
| CAMS | Detailed, Summary | mailback.camsonline.com request |
| KFintech | Detailed, Summary | mfs.kfintech.com request |
| NSDL | Demat consolidated | NSDL CAS email (monthly) |
| CDSL | Demat consolidated | CDSL CAS email (monthly) |
Known unsupported inputs
- Re-printed PDFs. If you "print to PDF" an existing CAS
(Microsoft Print to PDF, "Save as PDF" via a browser print
dialog, macOS print preview → save, etc.) the watermark gets
flattened from selectable text into a bitmap and the original
generator metadata is wiped. The visual appearance is
identical but
casparsercan no longer prove what it's looking at, and will reject the file. Re-request the statement from the issuer directly and parse the original. - MF Central statements. MF Central's CAS uses a different template / generator and is not in scope for v1.0.
- Third-party-reformatted statements (broker portals that re-render CAS data, Excel/CSV exports converted back to PDF, etc.) — same reason as re-prints.
If you need to support one of these flows for downstream
tooling, the recommended path is to keep the original
issuer-delivered PDF alongside any redistributed copy and feed
the original to casparser.
Installation
pip install -U casparser
Since v1.0 the parser is built on pypdfium2 (Apache-2.0 / BSD-3) — no optional PDF backends, no GPL/AGPL dependencies.
Usage
import casparser
data = casparser.read_cas_pdf("/path/to/cas/file.pdf", "password")
# Get data in json format
json_str = casparser.read_cas_pdf("/path/to/cas/file.pdf", "password", output="json")
# Get transactions data in csv string format
csv_str = casparser.read_cas_pdf("/path/to/cas/file.pdf", "password", output="csv")
Data structure
{
"statement_period": {
"from": "YYYY-MMM-DD",
"to": "YYYY-MMM-DD"
},
"file_type": "CAMS/KFINTECH/NSDL/CDSL/UNKNOWN",
"cas_type": "DETAILED/SUMMARY",
"investor_info": {
"email": "string",
"name": "string",
"mobile": "string",
"address": "string"
},
"folios": [
{
"folio": "string",
"amc": "string",
"PAN": "string",
"KYC": "OK/NOT OK",
"PANKYC": "OK/NOT OK",
"schemes": [
{
"scheme": "string",
"isin": "string",
"amfi": "string",
"advisor": "string",
"rta_code": "string",
"rta": "string",
"type": "string",
"nominees": [
"string",
],
"open": "number",
"close": "number",
"close_calculated": "number",
"valuation": {
"date": "date",
"nav": "number",
"value": "number",
"cost": "number",
},
"transactions": [
{
"date": "YYYY-MM-DD",
"description": "string",
"amount": "number",
"units": "number",
"nav": "number",
"balance": "number",
"type": "string",
"dividend_rate": "number"
}
]
}
]
}
]
}
Notes:
- Transaction
typecan be any value from the followingPURCHASEPURCHASE_SIPREDEMPTIONSWITCH_INSWITCH_IN_MERGERSWITCH_OUTSWITCH_OUT_MERGERDIVIDEND_PAYOUTDIVIDEND_REINVESTMENTSEGREGATIONSTAMP_DUTY_TAXTDS_TAXSTT_TAXMISC
dividend_rateis applicable only forDIVIDEND_PAYOUTandDIVIDEND_REINVESTMENTtransactions.- NSDL and CDSL statements return a different top-level shape with
accounts[].equities[]andaccounts[].mutual_funds[]instead offolios[].schemes[]. Seecasparser.types.NSDLCASDatafor details.
CLI
casparser also comes with a command-line interface that prints summary of parsed portfolio in a wide variety of formats.
Usage: casparser [-o output_file.json|output_file.csv] [-p password] [-s] [-a] CAS_PDF_FILE
-o, --output FILE Output file path. Saves the parsed data as json or csv
depending on the file extension. For other extensions, the
summary output is saved. [See note below]
-s, --summary Print Summary of transactions parsed.
-p PASSWORD CAS password
-a, --include-all Include schemes with zero valuation in the
summary output
-g, --gains Generate Capital Gains Report (BETA)
--gains-112a ask|FY2020-21 Generate Capital Gains Report - 112A format for
a given financial year - Use 'ask' for a prompt
from available options (BETA)
--version Show the version and exit.
-h, --help Show this message and exit.
CLI examples
# Print portfolio summary
casparser /path/to/cas.pdf -p password
# Print portfolio and capital gains summary
casparser /path/to/cas.pdf -p password -g
# Save parsed data as a json file
casparser /path/to/cas.pdf -p password -o pdf_parsed.json
# Save parsed data as a csv file
casparser /path/to/cas.pdf -p password -o pdf_parsed.csv
# Save capital gains transactions in csv files (pdf_parsed-gains-summary.csv and
# pdf_parsed-gains-detailed.csv)
casparser /path/to/cas.pdf -p password -g -o pdf_parsed.csv
Note: casparser cli supports two special output file formats [-o file.json / file.csv]
json- complete parsed data is exported in json format (including investor info)csv- Summary info is exported in csv format if the input file is a summary statement or if a summary flag (-s/--summary) is passed as argument to the CLI. Otherwise, full transaction history is included in the export. If-gflag is present, two additional files '{basename}-gains-summary.csv', '{basename}-gains-detailed.csv' are created with the capital-gains data.- any other extension - The summary table is saved in the file.
Demo
ISIN & AMFI code support
Since v0.4.3, casparser includes support for identifying ISIN and AMFI code for the parsed schemes
via the helper module casparser-isin. If the parser
fails to assign ISIN or AMFI codes to a scheme, try updating the local ISIN database by
casparser-isin --update
If it still fails, please raise an issue at casparser-isin with the failing scheme name(s).
License
CASParser is distributed under the MIT license. Up to v0.8 the optional
mupdf / fast extra pulled in PyMuPDF /
MuPDF, which would have caused GNU GPL v3
and GNU Affero GPL v3 to apply transitively. v1.0 dropped that extra
(the PyMuPDF and pdfminer.six backends are gone; the parser now runs on
pypdfium2, which is dual
Apache-2.0 / BSD-3), so casparser is now pure MIT end-to-end.
Resources
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file casparser-1.0.0.tar.gz.
File metadata
- Download URL: casparser-1.0.0.tar.gz
- Upload date:
- Size: 67.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc998ab93b1daac79455fcd8cbc8f18aedb3f26b9d302eba6e9758d9d0150f80
|
|
| MD5 |
0f8430f3cbc8eb2c24e2a4f8930d9340
|
|
| BLAKE2b-256 |
74c6f1560466e89b1bdb6d7f9aa3ef7f4cbaf4afc2f4c7ad4e3410ebc5f5ae41
|
File details
Details for the file casparser-1.0.0-py3-none-any.whl.
File metadata
- Download URL: casparser-1.0.0-py3-none-any.whl
- Upload date:
- Size: 77.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a304ba91deec2a278782bbd708e15613cce013f571ffc630c66dd22f3d1e06b8
|
|
| MD5 |
5249270ccbf6cc51f0e767a172fba34e
|
|
| BLAKE2b-256 |
77bc2992cb5aa1793d4cb03c09631144b9ed560fa4b8d5f98577a68b5d85f0d7
|