Code Monkey home page Code Monkey logo

async-stripe's Introduction

async-stripe

Build Status

An asynchronous wrapper around Stripe's official python library.

How it works

async-stripe monkey-patches the stripe library and replaces the synchronous http request methods with asynchronous methods.

Monkey-patching allows us to avoid a complete rewrite and keep the usage api similar to the official library.

This doesn't use threads, but actual async coroutines and non-blocking http client to make requests. Hence, the performance is much better than other wrapper libraries which use threading.

Install

Install requires Python 3.6 or newer.

$ pip install async-stripe

Usage

The usage api is similar to Stripe's official library:

from async_stripe import stripe

stripe.api_key = '<stripe-secret-key>'

payment_intent = await stripe.PaymentIntent.create(amount=1000, currency='usd')

print(payment_intent.id)

/!\ Note: Since this library monkey-patches the actual stripe library, you should avoid using the two in the same process.

Once you import async_stripe, the official stripe library gets patched with async methods and the original synchronous api won't be available.


Configuration

Please see stripe-python's README file for configuring logging and other things.

Unsupported configurations:

async-stripe aims to be a drop-in async replacement for stripe. However, there are a few things which are not yet supported:

  • Custom http client: Currently, it's not possible to configure a custom http client and Tornado's AsyncHTTPClient will be used by default.
  • Proxy: Connecting to api via a proxy is not supported yet.

Development and Testing

When adding new features and monkey-patches, please add relevant tests and ensure that all the tests also pass.

In most cases, you shouldn't need to write the tests yourself: you can just copy-paste the tests form the original stripe library and change the synchronous methods to asynchronous methods.

For testing, first, install and run the stripe-mock api server.

Next, install pytest, pytest-mock and pytest-asyncio python packages in your virtualenv.

Finally, run the tests like this:

$ pytest tests

# or run a specific test
$ pytest tests/api_resources/test_customer.py
$ pytest tests/api_resources/test_customer.py::TestCustomer

License

A lot of the code (especially tests) are copied with slight modifications from Stripe's official library. That code is licensed under MIT License.

Rest of the original code is licensed under BSD-3-Clause License.

async-stripe's People

Contributors

bhch avatar cglacet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.