A Python library for interacting with the Personal Capital API. Easily log in, handle two-factor authentication, and fetch financial data like account details and net worth. Simplify automation and data retrieval from your Personal Capital account with this lightweight and user-friendly package.
Project description
Empower Personal Capital
A modern Python library for accessing your Personal Capital (Empower) data, with built-in support for session persistence, two-factor authentication, and convenient account and transaction retrieval.
Features
- Simple login: Email/password authentication
- Two-factor authentication: SMS and email support
- Session persistence: Avoids 2FA every run
- Fetch financial data: Account details, transactions, net worth
- Easy automation: Ideal for scripts and data analysis
Installation
With pip
pip install empower_personal_capital
From Source
Clone the repo:
git clone https://github.com/ChocoTonic/personalcapital-py.git
cd personalcapital-py
Install dependencies and the package:
pip install -r requirements.txt
python setup.py install
Usage
Quick Example
from personalcapital import PersonalCapital, RequireTwoFactorException, TwoFactorVerificationModeEnum
pc = PersonalCapital()
email, password = "you@example.com", "your_password"
try:
pc.login(email, password)
except RequireTwoFactorException:
pc.two_factor_challenge(TwoFactorVerificationModeEnum.SMS)
code = input("Enter 2FA code: ")
pc.two_factor_authenticate(TwoFactorVerificationModeEnum.SMS, code)
pc.authenticate_password(password)
accounts_response = pc.fetch('/newaccount/getAccounts')
accounts = accounts_response.json()['spData']
print('Net worth:', accounts['networth'])
Session Persistence
You can avoid having to enter 2FA every time by storing your session:
session = pc.get_session()
# Save session to a file
# Later...
pc.set_session(session)
See main.py for a complete script with persistent sessions.
Running the Example Script
The included main.py script provides a full working example with session saving/loading.
To run:
python main.py
You can also set environment variables to avoid entering your email and password each time:
PEW_EMAIL="you@example.com" PEW_PASSWORD="your_password" python main.py
If you do not set environment variables, the script will prompt for your credentials.
Absolutely. Here’s a clear section you can add to your README that explains the .env file usage and lists the required variables.
Environment Variables and the .env File
You can define your credentials in a .env file at the root of your project to avoid entering your email and password every time you run the script. The package will automatically load these using python-dotenv.
Create a file named .env and add your credentials:
PEW_EMAIL=your_email@example.com
PEW_PASSWORD=your_password
.env.example is included as a template. Never commit your real .env file with credentials to version control.
If these variables are set, the script will use them and will not prompt for your email or password.
Fetching Transactions
You can fetch transactions by making an API call. For example, to get transactions from the past 90 days (as shown in main.py):
from datetime import datetime, timedelta
now = datetime.now()
start_date = (now - timedelta(days=91)).strftime('%Y-%m-%d')
end_date = (now - timedelta(days=1)).strftime('%Y-%m-%d')
transactions_response = pc.fetch(
'/transaction/getUserTransactions',
{
"sort_cols": "transactionTime",
"sort_rev": "true",
"page": "0",
"rows_per_page": "100",
"startDate": start_date,
"endDate": end_date,
"component": "DATAGRID",
},
)
transactions = transactions_response.json()['spData']['transactions']
print(f"Found {len(transactions)} transactions")
Advanced Usage
-
Handling two-factor via Email: Replace
TwoFactorVerificationModeEnum.SMSwithTwoFactorVerificationModeEnum.EMAILin the challenge and authenticate methods. -
Other API endpoints: You can inspect your browser’s network requests while using Personal Capital, or refer to the code and experiment with additional endpoints using
pc.fetch(endpoint, data).
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 Distributions
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 empower_personal_capital-0.0.2-py3-none-any.whl.
File metadata
- Download URL: empower_personal_capital-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.14.0a4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
700e2dadfc69b015f52e40b0d3f83e6202f64224bec3b5f2214504e7667f2b3c
|
|
| MD5 |
9922695cd0d758dce8aa0a13de349214
|
|
| BLAKE2b-256 |
ac8776b03aaf3167668124eefd093986d3e04363b48ed913203470312aad48bf
|