faststripe


Namefaststripe JSON
Version 2025.6.30.0 PyPI version JSON
download
home_pagehttps://github.com/AnswerDotAI/faststripe
SummaryFastest way to use the Stripe API in python
upload_time2025-07-08 22:57:05
maintainerNone
docs_urlNone
authorncoop57
requires_python>=3.9
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Tutorial: Get Started with FastStripe


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Prerequisites

Before starting this tutorial, you’ll need:

- Python 3.8 or higher installed
- A Stripe account (sign up at [stripe.com](https://stripe.com))
- Your Stripe test API keys from the [Stripe
  Dashboard](https://dashboard.stripe.com/test/apikeys)

## Why FastStripe?

FastStripe offers several advantages over the official Stripe Python
SDK:

- **Self-documenting**: See all available parameters with descriptions
  in your IDE
- **Simplified workflows**: High-level methods for common payment
  patterns
- **Lightweight**: Minimal dependencies (just `fastcore`)
- **Consistent API**: HTTP verb-based methods (`post`, `get`) with full
  parameter visibility

## Step 1: Installation

First, install FastStripe using pip:

``` bash
pip install faststripe
```

Or install the latest development version:

``` bash
pip install git+https://github.com/AnswerDotAI/faststripe.git
```

## Versioning

FastStripe versions follow Stripe’s API versioning scheme (e.g.,
`2025.05.28.x`). Each FastStripe release is pinned to a specific Stripe
API version, ensuring:

- **Stability**: Your code won’t break when Stripe updates their API
- **Predictability**: Same behavior across all environments  
- **Compatibility**: Choose the Stripe API version that works for your
  application

When you install FastStripe, you get a specific snapshot of the Stripe
API that’s been tested and validated. The minor version represents
non-breaking changes we add such as better higher-level APIs.

## Step 2: Set up your API key

For this tutorial, you’ll use your Stripe test API key. Create a `.env`
file in your project directory:

``` bash
echo "STRIPE_SECRET_KEY=sk_test_your_test_key_here" > .env
```

Then load it in your Python environment:

## Step 3: Initialize FastStripe

Now let’s import FastStripe and initialize it with your API key:

``` python
from faststripe.core import StripeApi

import os

# Initialize with your API key from environment
sapi = StripeApi(os.environ['STRIPE_SECRET_KEY'])
```

``` python
# Create a customer
customer = sapi.customers.post(email='user@example.com', name='John Doe')
print(customer.id, customer.email)
```

    cus_ScUPG9yb5cPV6G user@example.com

### Self-Documenting API

One of FastStripe’s key advantages is that all methods include parameter
documentation directly in your IDE. You can see what parameters are
available without checking external docs:

``` python
# Explore available methods and their parameters
sapi.customers.post?
```

    Signature:     
    sapi.customers.post(
        address: object = None,
        balance: int = None,
        cash_balance: dict = None,
        description: str = None,
        email: str = None,
        ...

It also supports tab completion when filling in parameters!

### High-Level Convenience Methods

FastStripe includes simplified methods for common payment workflows:

``` python
# Create a one-time payment checkout session
checkout = sapi.one_time_payment(
    product_name='My Product',
    amount_cents=2000,  # $20.00
    success_url='https://localhost:8000/success',
    cancel_url='https://localhost:8000/cancel'
)
print(f"Payment URL: {checkout.url[:64]}...")
```

    Payment URL: https://billing.answer.ai/c/pay/cs_test_a107uQXcqI6W9iD09wOmVinc...

``` python
# Create a subscription checkout session
subscription = sapi.subscription(
    product_name='Monthly Plan',
    amount_cents=999,  # $9.99/month
    success_url='https://localhost:8000/success',
    cancel_url='https://localhost:8000/cancel',
    customer_email=customer.email
)
print(f"Subscription URL: {subscription.url[:64]}...")
```

    Subscription URL: https://billing.answer.ai/c/pay/cs_test_a1O4fjw1mgs11zkLGgHZTp6T...

### Complete API Coverage

FastStripe provides access to the entire Stripe API through organized
resource groups:

``` python
# Access any Stripe resource with consistent patterns
product = sapi.products.post(name='New Product')
print(f"Created product: {product.name} with ID: {product.id}")
```

    Created product: New Product with ID: prod_ScUPzNzla8KDC6

``` python
# Fetch existing resources
customers = sapi.customers.get(limit=3)
print(f"Found {len(customers.data)} customers")
```

    Found 3 customers

``` python
# All responses are AttrDict objects for easy dot notation access
payment_intent = sapi.payment.intents_post(amount=1000, currency='usd')
print(f"Payment intent status: {payment_intent.status}, amount: ${payment_intent.amount/100}")
```

    Payment intent status: requires_payment_method, amount: $10.0

### Pagination Support

FastStripe includes built-in utilities for handling paginated API
responses, making it easy to work with large requests.

``` python
from faststripe.page import paged, pages


for p in paged(sapi.customers.get, limit=5): break
print(f"Got {len(p.data)} customers")
print(f"Has more pages: {p.has_more}")
```

    Got 5 customers
    Has more pages: True

``` python
sapi.products
```

<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"></pre>

- [products.get](https://docs.stripe.com/api/products/list)(active:
  ‘str’, created: ‘str’, ending_before: ‘str’, expand: ‘str’, ids:
  ‘str’, limit: ‘str’, shippable: ‘str’, starting_after: ‘str’, url:
  ‘str’): *List all products*
- [products.post](https://docs.stripe.com/api/products/create)(active:
  bool = None, default_price_data: dict = None, description: str = None,
  expand: list = None, id: str = None, images: list = None,
  marketing_features: list = None, metadata: dict = None, name: str =
  None, package_dimensions: dict = None, shippable: bool = None,
  statement_descriptor: str = None, tax_code: str = None, unit_label:
  str = None, url: str = None): *Create a product*
- [products.search_get](https://docs.stripe.com/api/searchs/retrieve)(expand:
  ‘str’, limit: ‘str’, page: ‘str’, query: ‘str’): *Search products*
- [products.id_delete](https://docs.stripe.com/api/products/delete)(id):
  *Delete a product*
- [products.id_get](https://docs.stripe.com/api/products/delete)(id,
  expand: ‘str’): *Retrieve a product*
- [products.id_post](https://docs.stripe.com/api/products/update)(id,
  active: bool = None, default_price: str = None, description: object =
  None, expand: list = None, images: object = None, marketing_features:
  object = None, metadata: object = None, name: str = None,
  package_dimensions: object = None, shippable: bool = None,
  statement_descriptor: str = None, tax_code: object = None, unit_label:
  object = None, url: object = None): *Update a product*
- [products.product_features_get](https://docs.stripe.com/api/features/delete)(product,
  ending_before: ‘str’, expand: ‘str’, limit: ‘str’, starting_after:
  ‘str’): *List all features attached to a product*
- [products.product_features_post](https://docs.stripe.com/api/features/update)(product,
  entitlement_feature: str = None, expand: list = None): *Attach a
  feature to a product*
- [products.product_features_id_delete](https://docs.stripe.com/api/features/delete)(product,
  id): *Remove a feature from a product*
- [products.product_features_id_get](https://docs.stripe.com/api/features/delete)(product,
  id, expand: ‘str’): *Retrieve a product_feature*

``` python
products = pages(sapi.products.get, limit=10)
len(products), products[0]
```

<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"></pre>


    (
        650,
        {
            'id': 'prod_ScUPzNzla8KDC6',
            'object': 'product',
            'active': True,
            'attributes': [],
            'created': 1751657895,
            'default_price': None,
            'description': None,
            'images': [],
            'livemode': False,
            'marketing_features': [],
            'metadata': {},
            'name': 'New Product',
            'package_dimensions': None,
            'shippable': None,
            'statement_descriptor': None,
            'tax_code': None,
            'type': 'service',
            'unit_label': None,
            'updated': 1751657895,
            'url': None
        }
    )

The pagination utilities work with any Stripe resource that supports
pagination:

- **[`paged()`](https://AnswerDotAI.github.io/faststripe/page.html#paged)**:
  Creates a paged generator for a resource’s API
- **[`pages()`](https://AnswerDotAI.github.io/faststripe/page.html#pages)**:
  Iterator that automatically fetches all pages and returns all items
  returned in those pages

This makes it easy to process large datasets without manually handling
pagination tokens.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AnswerDotAI/faststripe",
    "name": "faststripe",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "nbdev jupyter notebook python",
    "author": "ncoop57",
    "author_email": "nathanacooper@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/83/fb/d8fa10f730d9b23545968aaf0bb0193cafeb89726b0ab830d05e6298f422/faststripe-2025.6.30.0.tar.gz",
    "platform": null,
    "description": "# Tutorial: Get Started with FastStripe\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Prerequisites\n\nBefore starting this tutorial, you\u2019ll need:\n\n- Python 3.8 or higher installed\n- A Stripe account (sign up at [stripe.com](https://stripe.com))\n- Your Stripe test API keys from the [Stripe\n  Dashboard](https://dashboard.stripe.com/test/apikeys)\n\n## Why FastStripe?\n\nFastStripe offers several advantages over the official Stripe Python\nSDK:\n\n- **Self-documenting**: See all available parameters with descriptions\n  in your IDE\n- **Simplified workflows**: High-level methods for common payment\n  patterns\n- **Lightweight**: Minimal dependencies (just `fastcore`)\n- **Consistent API**: HTTP verb-based methods (`post`, `get`) with full\n  parameter visibility\n\n## Step 1: Installation\n\nFirst, install FastStripe using pip:\n\n``` bash\npip install faststripe\n```\n\nOr install the latest development version:\n\n``` bash\npip install git+https://github.com/AnswerDotAI/faststripe.git\n```\n\n## Versioning\n\nFastStripe versions follow Stripe\u2019s API versioning scheme (e.g.,\n`2025.05.28.x`). Each FastStripe release is pinned to a specific Stripe\nAPI version, ensuring:\n\n- **Stability**: Your code won\u2019t break when Stripe updates their API\n- **Predictability**: Same behavior across all environments  \n- **Compatibility**: Choose the Stripe API version that works for your\n  application\n\nWhen you install FastStripe, you get a specific snapshot of the Stripe\nAPI that\u2019s been tested and validated. The minor version represents\nnon-breaking changes we add such as better higher-level APIs.\n\n## Step 2: Set up your API key\n\nFor this tutorial, you\u2019ll use your Stripe test API key. Create a `.env`\nfile in your project directory:\n\n``` bash\necho \"STRIPE_SECRET_KEY=sk_test_your_test_key_here\" > .env\n```\n\nThen load it in your Python environment:\n\n## Step 3: Initialize FastStripe\n\nNow let\u2019s import FastStripe and initialize it with your API key:\n\n``` python\nfrom faststripe.core import StripeApi\n\nimport os\n\n# Initialize with your API key from environment\nsapi = StripeApi(os.environ['STRIPE_SECRET_KEY'])\n```\n\n``` python\n# Create a customer\ncustomer = sapi.customers.post(email='user@example.com', name='John Doe')\nprint(customer.id, customer.email)\n```\n\n    cus_ScUPG9yb5cPV6G user@example.com\n\n### Self-Documenting API\n\nOne of FastStripe\u2019s key advantages is that all methods include parameter\ndocumentation directly in your IDE. You can see what parameters are\navailable without checking external docs:\n\n``` python\n# Explore available methods and their parameters\nsapi.customers.post?\n```\n\n    Signature:     \n    sapi.customers.post(\n        address: object = None,\n        balance: int = None,\n        cash_balance: dict = None,\n        description: str = None,\n        email: str = None,\n        ...\n\nIt also supports tab completion when filling in parameters!\n\n### High-Level Convenience Methods\n\nFastStripe includes simplified methods for common payment workflows:\n\n``` python\n# Create a one-time payment checkout session\ncheckout = sapi.one_time_payment(\n    product_name='My Product',\n    amount_cents=2000,  # $20.00\n    success_url='https://localhost:8000/success',\n    cancel_url='https://localhost:8000/cancel'\n)\nprint(f\"Payment URL: {checkout.url[:64]}...\")\n```\n\n    Payment URL: https://billing.answer.ai/c/pay/cs_test_a107uQXcqI6W9iD09wOmVinc...\n\n``` python\n# Create a subscription checkout session\nsubscription = sapi.subscription(\n    product_name='Monthly Plan',\n    amount_cents=999,  # $9.99/month\n    success_url='https://localhost:8000/success',\n    cancel_url='https://localhost:8000/cancel',\n    customer_email=customer.email\n)\nprint(f\"Subscription URL: {subscription.url[:64]}...\")\n```\n\n    Subscription URL: https://billing.answer.ai/c/pay/cs_test_a1O4fjw1mgs11zkLGgHZTp6T...\n\n### Complete API Coverage\n\nFastStripe provides access to the entire Stripe API through organized\nresource groups:\n\n``` python\n# Access any Stripe resource with consistent patterns\nproduct = sapi.products.post(name='New Product')\nprint(f\"Created product: {product.name} with ID: {product.id}\")\n```\n\n    Created product: New Product with ID: prod_ScUPzNzla8KDC6\n\n``` python\n# Fetch existing resources\ncustomers = sapi.customers.get(limit=3)\nprint(f\"Found {len(customers.data)} customers\")\n```\n\n    Found 3 customers\n\n``` python\n# All responses are AttrDict objects for easy dot notation access\npayment_intent = sapi.payment.intents_post(amount=1000, currency='usd')\nprint(f\"Payment intent status: {payment_intent.status}, amount: ${payment_intent.amount/100}\")\n```\n\n    Payment intent status: requires_payment_method, amount: $10.0\n\n### Pagination Support\n\nFastStripe includes built-in utilities for handling paginated API\nresponses, making it easy to work with large requests.\n\n``` python\nfrom faststripe.page import paged, pages\n\n\nfor p in paged(sapi.customers.get, limit=5): break\nprint(f\"Got {len(p.data)} customers\")\nprint(f\"Has more pages: {p.has_more}\")\n```\n\n    Got 5 customers\n    Has more pages: True\n\n``` python\nsapi.products\n```\n\n<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n\n- [products.get](https://docs.stripe.com/api/products/list)(active:\n  \u2018str\u2019, created: \u2018str\u2019, ending_before: \u2018str\u2019, expand: \u2018str\u2019, ids:\n  \u2018str\u2019, limit: \u2018str\u2019, shippable: \u2018str\u2019, starting_after: \u2018str\u2019, url:\n  \u2018str\u2019): *List all products*\n- [products.post](https://docs.stripe.com/api/products/create)(active:\n  bool = None, default_price_data: dict = None, description: str = None,\n  expand: list = None, id: str = None, images: list = None,\n  marketing_features: list = None, metadata: dict = None, name: str =\n  None, package_dimensions: dict = None, shippable: bool = None,\n  statement_descriptor: str = None, tax_code: str = None, unit_label:\n  str = None, url: str = None): *Create a product*\n- [products.search_get](https://docs.stripe.com/api/searchs/retrieve)(expand:\n  \u2018str\u2019, limit: \u2018str\u2019, page: \u2018str\u2019, query: \u2018str\u2019): *Search products*\n- [products.id_delete](https://docs.stripe.com/api/products/delete)(id):\n  *Delete a product*\n- [products.id_get](https://docs.stripe.com/api/products/delete)(id,\n  expand: \u2018str\u2019): *Retrieve a product*\n- [products.id_post](https://docs.stripe.com/api/products/update)(id,\n  active: bool = None, default_price: str = None, description: object =\n  None, expand: list = None, images: object = None, marketing_features:\n  object = None, metadata: object = None, name: str = None,\n  package_dimensions: object = None, shippable: bool = None,\n  statement_descriptor: str = None, tax_code: object = None, unit_label:\n  object = None, url: object = None): *Update a product*\n- [products.product_features_get](https://docs.stripe.com/api/features/delete)(product,\n  ending_before: \u2018str\u2019, expand: \u2018str\u2019, limit: \u2018str\u2019, starting_after:\n  \u2018str\u2019): *List all features attached to a product*\n- [products.product_features_post](https://docs.stripe.com/api/features/update)(product,\n  entitlement_feature: str = None, expand: list = None): *Attach a\n  feature to a product*\n- [products.product_features_id_delete](https://docs.stripe.com/api/features/delete)(product,\n  id): *Remove a feature from a product*\n- [products.product_features_id_get](https://docs.stripe.com/api/features/delete)(product,\n  id, expand: \u2018str\u2019): *Retrieve a product_feature*\n\n``` python\nproducts = pages(sapi.products.get, limit=10)\nlen(products), products[0]\n```\n\n<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n\n\n    (\n        650,\n        {\n            'id': 'prod_ScUPzNzla8KDC6',\n            'object': 'product',\n            'active': True,\n            'attributes': [],\n            'created': 1751657895,\n            'default_price': None,\n            'description': None,\n            'images': [],\n            'livemode': False,\n            'marketing_features': [],\n            'metadata': {},\n            'name': 'New Product',\n            'package_dimensions': None,\n            'shippable': None,\n            'statement_descriptor': None,\n            'tax_code': None,\n            'type': 'service',\n            'unit_label': None,\n            'updated': 1751657895,\n            'url': None\n        }\n    )\n\nThe pagination utilities work with any Stripe resource that supports\npagination:\n\n- **[`paged()`](https://AnswerDotAI.github.io/faststripe/page.html#paged)**:\n  Creates a paged generator for a resource\u2019s API\n- **[`pages()`](https://AnswerDotAI.github.io/faststripe/page.html#pages)**:\n  Iterator that automatically fetches all pages and returns all items\n  returned in those pages\n\nThis makes it easy to process large datasets without manually handling\npagination tokens.\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Fastest way to use the Stripe API in python",
    "version": "2025.6.30.0",
    "project_urls": {
        "Homepage": "https://github.com/AnswerDotAI/faststripe"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2abbe6c654ff4cffa2271509cf93deacf753c24225d0429008aed9cc00f2a5ec",
                "md5": "badf06fcc1141a0dcf2f8690660ad668",
                "sha256": "66f121f645f22c9ffa80ab859d23691d3f12a8807802713f0245f604a6aa5320"
            },
            "downloads": -1,
            "filename": "faststripe-2025.6.30.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "badf06fcc1141a0dcf2f8690660ad668",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 104200,
            "upload_time": "2025-07-08T22:57:04",
            "upload_time_iso_8601": "2025-07-08T22:57:04.246645Z",
            "url": "https://files.pythonhosted.org/packages/2a/bb/e6c654ff4cffa2271509cf93deacf753c24225d0429008aed9cc00f2a5ec/faststripe-2025.6.30.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "83fbd8fa10f730d9b23545968aaf0bb0193cafeb89726b0ab830d05e6298f422",
                "md5": "5cdfcc13240c5fb0ab9273c829817550",
                "sha256": "e1691f81836c323fb4fe5d8ee2e86280ab66c0996a20ee17f33c3db4de962dcd"
            },
            "downloads": -1,
            "filename": "faststripe-2025.6.30.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5cdfcc13240c5fb0ab9273c829817550",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 106923,
            "upload_time": "2025-07-08T22:57:05",
            "upload_time_iso_8601": "2025-07-08T22:57:05.175294Z",
            "url": "https://files.pythonhosted.org/packages/83/fb/d8fa10f730d9b23545968aaf0bb0193cafeb89726b0ab830d05e6298f422/faststripe-2025.6.30.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-08 22:57:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AnswerDotAI",
    "github_project": "faststripe",
    "github_not_found": true,
    "lcname": "faststripe"
}
        
Elapsed time: 1.15456s