Skip to content

joshhubert-dsp/py-venmo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Venmo API - Updated Fork

This is a fork of mmohades' python venmo api package, which is no longer maintained, and therefore some features/payloads (notably payments) no longer worked. I took the liberty of fixing payment functionality, adding additional endpoints, and refactoring it almost beyond recognition. To be specific, this uses the mobile Venmo app API, the browser version is quite different.

FORK UPDATES

  • Payments work again! Credit to Joseph Charles for adding eligibility token support and laying the groundwork.
  • Added PaymentApi.get_transfer_destinations() and PaymentApi.initiate_transfer() for standard/instant transfers to bank/card.
  • Requires Python 3.11+, using a pyproject.toml (uv friendly) and modern language features.
  • The data models now use pydantic-v2, removing a bunch of boilerplate.
  • Set the env var LOGGING_SESSION to print the raw requests sent and responses received.
  • venmo.Client has context manager dunder methods for with block logout using a stored access token.
  • I got rid of the threaded-async callback functionality, because it added complexity that I didn't see as useful. In my experience Venmo is now quick to pump the brakes on anyone hitting the API too rapidly. This manifests in the dreaded 403 response: "OAuth2 Exception: Unable to complete your request. Please try again later", locking you out of your account with a variable cooldown time.
  • Request headers now mirror the actual app's as closely as possible. The default headers live in default_headers.json.
  • All code docstrings have been updated with changes.

TODO

  • Update Sphinx docs.
  • Get the original creator's blessing to submit package to PyPi with a new name.

Device ID Rigmarole

In my experience, the random device IDs generated by default are no longer accepted by the API. I had to grab my iPhone's actual device ID from the app's request headers to get it to cooperate. I did that using the mitmproxy command line tool, routing my phone's WiFi connection through the proxy, and grabbing it from the aptly named header device-id present in any request to https://api.venmo.com/v1. Good instructions here. Luckily you only have to do this once, the ID is fixed.

$ brew install mitmproxy
# You'll route your WiFi through your desktop IP address, port 8080
$ mitmweb --listen-host 0.0.0.0 --listen-port 8080 --web-port 8081

ORIGINAL README BELOW

Disclaimer: This is an individual effort and is not PayPal/Venmo sponsored or maintained.

Introduction

This library provides a Python wrapper for the Venmo API, using synchronous requests.

Installing

You can install or upgrade venmo-api with:

$ pip3 install venmo-api --upgrade

Or you can install it from the source:

$ git clone https://github.com/mmohades/Venmo.git --recursive
$ cd Venmo
$ python3 setup.py install

Getting Started

Usage

To use the API client, you first need to get your account's access token. Store your access token somewhere safe as anyone with the token can do everything with your Venmo account (e.g., transferring money). Also, make sure to revoke your access token once you are done using it using log_out().

from venmo_api import Client

# Get your access token. You will need to complete the 2FA process
# Please store it somewhere safe and use it next time
# Never commit your credentials or token to a git repository
access_token = Client.get_access_token(username='myemail@random.com',
                                        password='your password')
print("My token:", access_token)

The following is an example of initializing and working with the api client.

access_token = "YOUR_ACCESS_TOKEN"

# Initialize api client using an access-token
client = Client(access_token=access_token)

# Search for users. You get a maximum of 50 results per request.
users = client.user.search_for_users(query="Peter")
for user in users:
   print(user.username)
Revoke token

Keep this in mind that your access token never expires! You will need to revoke it yoursef:

client.log_out("Bearer a40fsdfhsfhdsfjhdkgljsdglkdsfj3j3i4349t34j7d")
Payment methods

Get all your payment methods to use one's id for sending_money

payment_methods = client.payment.get_payment_methods()
for payment_method in payment_methods:
    print(payment_method.to_json())
Sending or requesting money
# Request money
client.payment.request_money(32.5, "house expenses", "0000000000000000000")
# Send money (with default payment method)
client.payment.send_money(13.68, "thanks for the 🍔", "0000000000000000000")

# Send money (with the provided payment method id)
client.payment.send_money(amount=13.68,
                          note="thanks for the 🍔",
                          target_user_id="0000000000000000000",
                          funding_source_id='9999999999999999999')
Transactions

Getting a user's transactions (only the ones that are visible to you, e.g, their public transactions)

# Max number of transactions per request is 50.
client.user.get_user_transactions(user_id='0000000000000000000')
Friends list
# Get a user's friend's list
users = client.user.get_user_friends_list(user_id='0000000000000000000')
for user in users:
    print(user)
Pagination

Here is a pagination example:

# Get all the transactions possible (prints 50 per request until nothing has left)
transactions = client.user.get_user_transactions(user_id='0000000000000000000')
while transactions:
    for transaction in transactions:
        print(transaction)

    print("\n" + "=" * 15 + "\n\tNEXT PAGE\n" + "=" * 15 + "\n")
    transactions = transactions.get_next_page()

Documentation

venmo-api's documentation lives at readthedocs.io.

Contributing

Contributions of all sizes are welcome. You can help with the wrapper documentation located in /docs. You can also help by reporting bugs. You can add more routes to both Venmo Unofficial API Documentation and the venmo-api wrapper.

Venmo Unofficial API Documentation

You can find and contribute to the Venmo Unofficial API Documentation.

About

Venmo API client for Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%