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.
- 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
pip install empower_personal_capitalClone the repo:
git clone https://github.com/ChocoTonic/personalcapital-py.git
cd personalcapital-pyInstall dependencies and the package:
pip install -r requirements.txt
python setup.py installfrom 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'])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.
The included main.py script provides a full working example with session saving/loading.
To run:
python main.pyYou 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.pyIf 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.
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.
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")-
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).