This repository is no longer actively maintained. Development and support have shifted to the TypeScript/JavaScript library at https://github.com/keithah/monarchmoney-ts.
Please use that repo for the most up-to-date code and support.
Python library for accessing Monarch Money data.
Huge shoutout to hammem for originally starting this project! This is simply a fork of his hard work to continue development and fix critical authentication issues.
This fork includes comprehensive improvements and implements features requested in the original repository:
- Fixed GraphQL Server Errors: Resolved "Something went wrong processing" errors in account queries
- Stable Account Fetching: Simplified GraphQL queries for reliable account data retrieval
- 404 Login Error Fixes: Automatic GraphQL fallback when REST endpoints return 404
- Enhanced Authentication: Proper headers (device-uuid, Origin) and email OTP support
- Advanced Error Recovery: Automatic session recovery and retry logic with exponential backoff
- Comprehensive Test Suite: 58 tests passing with full CI/CD pipeline
πΌ Investment Management (implements Issue #112)
- β Add Holdings API: Complete manual holdings management
create_manual_holding()- Add holdings by security ID or tickerupdate_holding_quantity()- Modify existing holdingsdelete_manual_holding()- Remove holdingsget_account_holdings()- Retrieve all holdings for accountsget_holding_by_ticker()- Lookup specific holdings
π Advanced Budget Management (implements PR #154)
- β Flexible Budgets Support: Full flexible budget API implementation
set_budget_amount()- Update budget amounts with flexible period supportget_budgets()- Retrieve budgets with flexible expense tracking- Support for
BudgetFlexMonthlyAmountsand flexible budget variability - Complete budget management with rollover and planning features
create_goal()- Create financial goals with target amounts and datesupdate_goal()- Modify existing goals and track progressdelete_goal()- Remove completed or unwanted goalsget_goals()- Retrieve all goals with progress tracking
get_cashflow()- Detailed income/expense analysis with category breakdownsget_cashflow_summary()- Key financial metrics and trendsget_bills()- Upcoming bills and payment tracking- Advanced financial planning and forecasting capabilities
Clone this repository from Git
git clone https://github.com/keithah/monarchmoney-enhanced.git
pip install monarchmoney-enhanced
Note: This package is published as monarchmoney-enhanced on PyPI to distinguish it from the original monarchmoney package while maintaining the same Python import structure.
There are two ways to use this library: interactive and non-interactive.
If you're using this library in something like iPython or Jupyter, you can run an interactive-login which supports multi-factor authentication:
from monarchmoney import MonarchMoney
mm = MonarchMoney()
await mm.interactive_login()This will prompt you for the email, password and, if needed, the multi-factor token.
For a non-interactive session, you'll need to create an instance and login:
from monarchmoney import MonarchMoney
mm = MonarchMoney()
await mm.login(email, password)This may throw a RequireMFAException. If it does, you'll need to get a multi-factor token and call the following method:
from monarchmoney import MonarchMoney, RequireMFAException
mm = MonarchMoney()
try:
await mm.login(email, password)
except RequireMFAException:
await mm.multi_factor_authenticate(email, password, multi_factor_code)Note: The library automatically detects whether your MFA code is an email OTP (6 digits) or TOTP from an authenticator app, and uses the appropriate authentication field.
Alternatively, you can provide the MFA Secret Key. The MFA Secret Key is found when setting up the MFA in Monarch Money by going to Settings -> Security -> Enable MFA -> and copy the "Two-factor text code". Then provide it in the login() method:
from monarchmoney import MonarchMoney, RequireMFAException
mm = MonarchMoney()
await mm.login(
email=email,
password=password,
save_session=False,
use_saved_session=False,
mfa_secret_key=mfa_secret_key,
)You can easily save your session for use later on. While we don't know precisely how long a session lasts, authors of this library have found it can last several months.
Sessions are stored using AES-256 encryption for security. The enhanced package ensures session persistence works reliably across processes and application restarts.
from monarchmoney import MonarchMoney, RequireMFAException
mm = MonarchMoney()
mm.interactive_login()
# Save it for later, no more need to login!
mm.save_session()Once you've logged in, you can simply load the saved session to pick up where you left off.
from monarchmoney import MonarchMoney, RequireMFAException
mm = MonarchMoney()
mm.load_session() # Works across processes and app restarts!
# Then, start accessing data!
await mm.get_accounts()This enhanced library provides comprehensive financial data access:
get_account_holdings(account_id)- Get all securities in investment accountscreate_manual_holding(account_id, symbol, quantity)- Add holdings by tickercreate_manual_holding_by_ticker(account_id, ticker, quantity)- Add holdings with ticker lookupupdate_holding_quantity(holding_id, quantity)- Modify existing holdingsdelete_manual_holding(holding_id)- Remove holdingsget_holding_by_ticker(ticker)- Lookup holdings by ticker symbol
get_budgets()- Get budgets with flexible budget supportset_budget_amount(category_id, amount)- Update budget amounts with flexible periodsget_goals()- Get financial goals with progress trackingcreate_goal(name, target_amount)- Create new financial goalsupdate_goal(goal_id, **kwargs)- Update existing goalsdelete_goal(goal_id)- Remove financial goalsget_cashflow()- Income/expense analysis with category breakdownsget_cashflow_summary()- Key financial metrics and trendsget_bills()- Upcoming bills and payment tracking
get_accounts()- Get all linked accounts (with GraphQL fixes)get_me()- Current user profile (timezone, email, name, MFA status)get_merchants()- Merchant list from transactionsget_account_type_options()- All available account types and subtypesget_account_history()- Daily account balance historyget_institutions()- Linked financial institutionsget_subscription_details()- Account status (paid/trial)get_recurring_transactions()- Future recurring transactionsget_transactions()- Transaction data with flexible date rangesget_transactions_summary()- Transaction summary from transactions pageget_transactions_summary_card()- Summary card data with totalsget_transaction_categories()- All configured transaction categoriesget_transaction_category_groups()- All category groupsget_transaction_details(transaction_id)- Detailed transaction dataget_transaction_splits(transaction_id)- Transaction split informationget_transaction_tags()- All configured transaction tagsget_recurring_transactions()- Recurring transaction streams and patternsmark_stream_as_not_recurring(stream_id)- Mark merchants as not recurringget_net_worth_history()- Net worth tracking over timeis_accounts_refresh_complete()- Account refresh status
create_manual_holding(account_id, symbol, quantity)- Create holdings by tickerupdate_holding_quantity(holding_id, quantity)- Update holding quantitiesdelete_manual_holding(holding_id)- Remove holdings from accounts
set_budget_amount(category_id, amount)- Set flexible budget amountscreate_goal(name, target_amount)- Create new financial goalsupdate_goal(goal_id, **kwargs)- Update existing goalsdelete_goal(goal_id)- Remove financial goals
create_manual_account(name, type, balance)- Create new manual accountsupdate_account(account_id, **kwargs)- Update account settings/balancedelete_account(account_id)- Delete accountsupload_account_balance_history(account_id, csv_file)- Upload balance historyrequest_accounts_refresh()- Non-blocking account sync refreshrequest_accounts_refresh_and_wait()- Blocking account sync refreshget_recent_account_balances(start_date)- Get balance history for all accounts- Note: AccountService also provides
get_recent_account_balances()with account filtering
- Note: AccountService also provides
create_transaction(account_id, amount, date, **kwargs)- Create transactionsupdate_transaction(transaction_id, **kwargs)- Update transaction attributesdelete_transaction(transaction_id)- Delete transactionsupdate_transaction_splits(transaction_id, splits)- Modify transaction splitscreate_transaction_category(name, **kwargs)- Create transaction categoriesupdate_transaction_category(category_id, **kwargs)- Update categoriesdelete_transaction_category(category_id)- Delete single categorydelete_transaction_categories(category_ids)- Delete multiple categoriescreate_transaction_tag(name)- Create transaction tagsset_transaction_tags(transaction_id, tag_ids)- Set tags on transactions
mark_stream_as_not_recurring(stream_id)- Mark merchants as not recurringget_edit_merchant(merchant_id)- Get merchant edit info with recurring detailsget_recurring_transactions()- Get upcoming recurring transactionsreview_recurring_stream(stream_id, status)- Review and approve recurring streams
validate_session- validates current session by making a lightweight API callis_session_stale- checks if session needs validation based on elapsed timeensure_valid_session- ensures session is valid, validating if staleget_session_info- gets session metadata (creation time, last validation, staleness)
Complete transaction rules management:
get_transaction_rules- Get all configured rules with criteria and actionscreate_transaction_rule- Create rules with merchant/amount/category/account criteriaupdate_transaction_rule- Update existing rule criteria and actionsdelete_transaction_rule- Delete individual rulesreorder_transaction_rules- Change rule execution orderpreview_transaction_rule- Preview rule effects before creatingdelete_all_transaction_rules- Delete all rules at oncecreate_categorization_rule- Helper for simple merchantβcategory rules
For a complete mapping of GraphQL operations and implementation status, see GRAPHQL.md.
This project includes a comprehensive test suite. To run tests:
# Install test dependencies
pip install pytest pytest-asyncio pytest-cov
# Run all tests
pytest
# Run with coverage
pytest --cov=monarchmoney --cov-report=term-missing
# Run specific test categories
pytest -m "api" # API method tests
pytest -m "auth" # Authentication tests
pytest -m "unit" # Unit tests- Authentication Tests: Login, MFA, session management, header validation
- API Method Tests: Account/transaction retrieval, GraphQL execution, error handling
- Integration Tests: End-to-end functionality and field detection
- Retry Logic Tests: Rate limiting, exponential backoff, error handling
This project uses GitHub Actions for continuous integration:
- Multi-Python Testing: Supports Python 3.8 through 3.12
- Code Quality: Automated linting with flake8, formatting with black, import sorting with isort
- Coverage Reporting: Integrated with Codecov for test coverage tracking
Any and all contributions -- code, documentation, feature requests, feedback -- are welcome!
If you plan to submit up a pull request, you can expect a timely review. Please ensure you do the following:
- Configure your IDE or manually run Black to auto-format the code.
- Ensure you run the unit tests in this project:
pytest
Actions are configured in this repo to run against all PRs and merges which will block them if a unit test fails or Black throws an error.
If you're experiencing login problems, this fork includes several fixes:
404 Login Errors: The library automatically falls back to GraphQL authentication if REST endpoints return 404.
403 Forbidden Errors: Ensure you're using the latest version which includes proper browser headers (device-uuid, Origin, User-Agent).
MFA Problems: The library automatically detects email OTP vs authenticator app codes:
- 6-digit numeric codes are treated as email OTP
- Other formats are treated as TOTP from authenticator apps
Rate Limiting: Built-in retry logic with exponential backoff handles temporary rate limits automatically.
How do I use this API if I login to Monarch via Google?
If you currently use Google or 'Continue with Google' to access your Monarch account, you'll need to set a password to leverage this API. You can set a password on your Monarch account by going to your security settings.
Don't forget to use a password unique to your Monarch account and to enable multi-factor authentication!
What makes this fork superior?
This enhanced fork is ahead of the original repository with implemented features that others are still requesting:
π― Requested Features Already Implemented:
- Issue #112: β Add Holdings API - Full investment management
- PR #154: β Flexible Budgets - Complete budget flexibility support
π§ Critical Issue Fixes:
- GraphQL Server Errors: Fixed "Something went wrong processing" errors
- 404 Authentication: Automatic GraphQL fallback for auth endpoints
- 403 Forbidden: Proper browser headers (device-uuid, Origin, User-Agent)
- MFA Detection: Smart email OTP vs TOTP field detection
- Session Recovery: Automatic session validation and recovery
π Advanced Features:
- Financial Goals Management: Complete CRUD operations for goal tracking
- Cash Flow Analysis: Detailed income/expense breakdowns and trends
- Bills Management: Payment tracking and due date monitoring
- Error Recovery: Exponential backoff retry logic for robustness
- Test Coverage: 58 passing tests with full CI/CD pipeline