Screenshot Zerodha portfolio pages, compile to PDF, and email it
Project description
Zerodha Portfolio Summary Mailer
Automates the process of logging into Zerodha, taking screenshots of key portfolio pages, compiling them into a PDF, and emailing the PDF to a recipient.
What it does
- Opens a visible browser and navigates to the Zerodha login page
- Waits for you to log in manually (supports OTP / 2FA)
- Screenshots each configured page
- For the Tradebook page, iterates through every segment (Equity, F&O, Currency, etc.) with a 3-month date range, and captures all pagination pages per segment
- Compiles all screenshots into a single PDF
- Opens the PDF for your review
- Sends the PDF by email only after you confirm
Requirements
- Python 3.10+
- A Gmail account with an App Password (see setup below)
Install dependencies
pip install playwright pillow img2pdf
playwright install chromium
Configuration
The program reads settings from config.ini. A template is provided — copy it and fill in your details:
cp config.ini.template config.ini
Then edit config.ini:
[settings]
base_url = https://kite.zerodha.com/ # Login page URL
pages = https://console.zerodha.com/reports/tradebook
https://console.zerodha.com/account/demat
https://console.zerodha.com/portfolio/corporate-action-order-window
https://coin.zerodha.com/dashboard
receiver_email = recipient@example.com # Who receives the PDF
sender_email = yourname@gmail.com # Gmail address used to send
password = your-gmail-app-password # Gmail App Password (see below)
smtp_host = smtp.gmail.com
smtp_port = 587
no_tls = false
subject = Zerodha Portfolio Summary
body = Please find the Zerodha screenshots attached as a PDF.
output_pdf = zerodha_summary.pdf
width = 1280 # Browser viewport width in pixels
Note:
config.iniis excluded from git (via.gitignore) to protect your credentials. Never commit it.
Gmail App Password setup
Gmail requires an App Password when 2-Step Verification is enabled:
- Go to Google Account → Security
- Under How you sign in to Google, click 2-Step Verification
- Scroll to the bottom and click App passwords
- Create a new app password (e.g. name it "Zerodha Mailer")
- Copy the 16-character password (spaces are optional) into
config.iniunderpassword
Pages configuration
- Each URL goes on its own line, indented under
pages = - The Tradebook page (
/reports/tradebook) is handled specially: the program automatically iterates all segments and date ranges - All other pages are screenshotted as-is (full page)
Running the program
python3 screenshot_to_pdf_mailer.py
What happens step by step
| Step | What you see |
|---|---|
| 1 | Browser opens to base_url (Zerodha login) |
| 2 | Log in with your credentials + OTP |
| 3 | Press Enter in the terminal to confirm login |
| 4 | Program navigates to each page and takes screenshots |
| 5 | For Tradebook: selects each segment, sets Dec 1 – today date range, captures all pages |
| 6 | PDF is compiled and opened in your PDF viewer |
| 7 | Type yes in the terminal to send the email, or anything else to cancel |
Overriding config from the command line
Any setting in config.ini can be overridden with a CLI argument:
python3 screenshot_to_pdf_mailer.py \
--receiver-email other@example.com \
--subject "March 2026 Summary" \
--output-pdf march_2026.pdf
Use --config to point to a different config file:
python3 screenshot_to_pdf_mailer.py --config my_other_config.ini
File structure
zerodha-summary/
├── screenshot_to_pdf_mailer.py # Main program
├── config.ini.template # Template — safe to commit
├── config.ini # Your local config — DO NOT commit
├── .gitignore # Excludes config.ini, *.pdf, *.png
└── README.md # This file
Troubleshooting
| Problem | Fix |
|---|---|
Missing dependency error |
Run pip install playwright pillow img2pdf and playwright install chromium |
| Gmail login fails | Make sure you are using an App Password, not your regular Gmail password |
| Tradebook segment not found | Check the [DOM] selects line printed in the terminal — the segment name must match exactly |
| Pagination not detected | Check the [pagination] line printed in the terminal for the actual button classes |
| PDF not opening | Install a PDF viewer (sudo apt install evince on Ubuntu) |
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 zerodha_summary-0.1.0.tar.gz.
File metadata
- Download URL: zerodha_summary-0.1.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b51bd50ea06de2bcc27e8558ee302e82d591db2b615494c130468d135a77a389
|
|
| MD5 |
cc59311ab9b643c37059b10572744254
|
|
| BLAKE2b-256 |
27dbd5fb2f132546a66ec0a45f45f0630c1fb8ffd53c25ecbae65c0460ffc495
|
File details
Details for the file zerodha_summary-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zerodha_summary-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
676845b4194ad40355dc4e3a7782153e716b47dbe08cf85d40685f1e02c1612f
|
|
| MD5 |
5012d93928600d3a22c3654af63fae92
|
|
| BLAKE2b-256 |
bc268ae1010db764091cb8bf78a40239666f564f3bba934e95df571e02034939
|