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
Personal Capital
Python library for accessing Personal Capital data
Installation
With Pip
pip install empower_personal_capital
With Source Code
You can get the source code by cloning it from Github:
git clone https://github.com/haochi/personalcapital.git
or get the tarball:
curl -OJL https://github.com/haochi/personalcapital/tarball/master
then either include the library into your code, or install it with:
python setup.py install
Usage
You need to first create an instance.
pc = PersonalCapital()
Then you will need to authenticate the account by logging in:
pc.login(email, password)
login may throw a RequireTwoFactorException, if two factor is enabled on your account and the current session is not yet associated with the account.
In this case, you will need to pick a way to complete the two factor authenticate by calling
pc.two_factor_challenge(mode)
mode can either be TwoFactorVerificationModeEnum.SMS or TwoFactorVerificationModeEnum.EMAIL.
Then you need to finish the two factor challenge by verifying the code and continue the login process.
pc.two_factor_authenticate(mode, raw_input('code'))
pc.authenticate_password(password)
Once authenticated, you can start fetching data from the Personal Capital API.
accounts_response = pc.fetch('/newaccount/getAccounts')
The above request will load your accounts data, and with that response you can get your net worth.
print('Networth', accounts_response.json()['spData']['networth'])
To avoid two factor authentication every time you run the script, you can use get_session() to store your session somewhere and set_session(session) to re-use the session.
Here's the entire thing.
from personalcapital import PersonalCapital, RequireTwoFactorException, TwoFactorVerificationModeEnum
pc = PersonalCapital()
email, password = "email@domain.tld", "password"
try:
pc.login(email, password)
except RequireTwoFactorException:
pc.two_factor_challenge(TwoFactorVerificationModeEnum.SMS)
pc.two_factor_authenticate(TwoFactorVerificationModeEnum.SMS, raw_input('code: '))
pc.authenticate_password(password)
accounts_response = pc.fetch('/newaccount/getAccounts')
accounts = accounts_response.json()['spData']
print('Networth: {0}'.format(accounts['networth']))
Example
See main.py for an example script.
To run it, simply run python main.py.
Or set the environment email and password so you don't need to enter it every time.
PEW_PASSWORD="password" PEW_EMAIL="email" python main.py
Personal Capital API
Please inspect the network requests to see what requests are possible. The main.py example includes two such calls.
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.1-py3-none-any.whl.
File metadata
- Download URL: empower_personal_capital-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 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 |
c673418a9933cdd5f01360f648ff5eba51baf6f9e1c03e638839a1944790d683
|
|
| MD5 |
ade0fdbe3511e65ba19a9c4f9051689b
|
|
| BLAKE2b-256 |
acfc464f17085b4f46a76808a6bf2b0f8077fd61c58dd305ef21e8341026f008
|