AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
Answer.AI·2025年7月23日 09:00·約15分で読める

あなたが求めるStripeの体験

#Stripe#決済システム#開発者ツール#OpenAPI#Python
TL;DR

Answer.AI の開発者が Stripe SDK の複雑さを解消し、コード量を大幅に削減して IDE 連携を強化したサードパーティライブラリ「FastStripe」を発表しました。

AI深層分析2026年5月3日 01:06
3
注目/ 5段階
深度40%
4
関連度30%
2
実用性20%
5
革新性10%
3

キーポイント

1

開発者体験(DX)の劇的改善

公式 SDK の複雑なパラメータ設定やドキュメント検索の手間を省き、IDE での補完機能と明確なドキュストリングを提供することで、コード記述量を約 60% 削減します。

2

具体的なコード効率化

ワンタイム決済の作成が公式 SDK の約 25 行から 6 行に、定期購読の設定も 9 行に短縮され、開発スピードと保守性が向上します。

3

OpenAPI スペック活用

Stripe が公開した OpenAPI スペックを基盤とし、常に最新 API バージョンに対応し続ける自動更新メカニズムを採用しています。

4

公式ドキュメントへの依存による開発効率の低下

Stripe の標準 API を使用する場合、パラメータの詳細を確認するために外部ドキュメントやソースコードを参照する必要があり、これが頻繁なコンテキストスイッチを引き起こして開発時間を浪費します。

5

FastStripe による開発体験の改善

著者は「怒り駆動型開発(RDD)」として FastStripe を構築し、複雑なパラメータ設定を省略した直感的なインターフェースを提供することで、決済機能の実装時間を数分から数時間に短縮しました。

6

OpenAPI Spec を活用した動的生成

Stripe の OpenAPI スペックを解析し、エンドポイントやパラメータ情報を抽出して Python SDK を動的に生成することで、常に最新の状態を保つ。

7

IDE 支援と開発体験の向上

自動生成されたドキュストリング(docstrings)とタブ補完機能により、IDE でパラメータの意味を確認しながら効率的にコードを書ける。

影響分析・編集コメントを表示

影響分析

このニュースは、決済処理という重要なインフラ領域において、サードパーティによる「DX 最適化」の価値を再認識させる事例です。大規模な公式 SDK の複雑さを、軽量で直感的なラッパーライブラリで解決するアプローチは、特にスタートアップや小規模チームの開発効率に大きなプラスの影響を与える可能性があります。

編集コメント

決済ライブラリの複雑さは多くの開発者の悩みの種ですが、OpenAPI スペックを活用したこのアプローチは、公式 SDK の弱点を補完する有望なパターンと言えます。

TL;DR

tldr: Stripe SDK で得ていた開発者体験に不満を感じ、より良いものとして FastStripe を作成しました。FastStripe は Stripe が公開した素晴らしい OpenAPI 仕様を活用して Stripe API の全機能をサポートしつつ、コードをよりクリーンにし、整理整頓を行い、IDE との統合も優れているため、パラメータの入力時に快適な補完機能を利用できます。また、関数の役割や各パラメータの意味を説明する明確なドキュストリング(docstrings)が用意されています。さらにヘルパー関数も追加されており、ワンタイム決済の実行は公式 SDK では約 25 行かかるものが FastStripe ではわずか 6 行で完了します。同様に、定期購読のセットアップについても、公式 SDK では約 25 行必要ですが、FastStripe では 9 行で実現可能です。

現在、すでに公開されており、ほぼ 1 ヶ月間にわたり弊社の内部アプリケーションを問題なく稼働させています。その間、複雑さを大幅に削減し続けてきました。使用を開始するには、pip install faststripe を実行し、最初のワンタイム決済リンクを作成するだけです:

from faststripe.core import StripeApi

sapi = StripeApi('your-key-here')

checkout = sapi.one_time_payment(product_name='Digital Course', amount_cents=49_99,

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1gQnoO5ezm5yFB47GZNWO6I...

私たちはまた、Stripe API の新しいバージョンごとに FastStripe を継続的に更新しています。

あなたがふさわしい Stripe エクスペリエンス

これが聞き慣れた話だと感じたら私を止めてください:人々のお金を集めたい、そしてそれを非常に簡単に実行できることを確認したい。まるで赤ん坊からキャンディを奪うように簡単です。もちろん、そのお金との交換として、その人が喜んでお金を支払ってくれるサービスや製品を提供したいと願うでしょう。これは以前は悪夢のようなものでしたし、一部の企業にとっては今でも悪夢のように感じられるかもしれません(咳、咳、Google)

image
image

Stripe はこのプロセスを非常に簡単にすると主張していますが、正直に言って、過去 8 ヶ月間に彼らの SDK(Software Development Kit:ソフトウェア開発キット)を使用しようとしたのは苦難の道でした。そしてそれは長い旅でした。あまりにも長く、またでこぼこしていたので、私はすぐにこれが実用にならないと悟りました。私が何を意味しているかをお見せしましょう。支払いを受け入れる典型的なプロセスは次のようになります。

import stripe

ステップ 0: Stripe API キーの設定

stripe.api_key = 'your-api-key'

ステップ 1: プロダクトの作成(パラメータを忘れないでください)

product = stripe.Product.create(name='Digital Course')

ステップ 2: プライスの作成(この関数にはどのようなパラメータが必要だったか?)

price = stripe.Price.create(product=product.id, unit_amount=4999, # 待て、これはセント単位ですかドル単位ですか?

currency='usd')

ステップ3:チェックアウトセッションの作成(ドキュメントを漁る時間)

checkout = stripe.checkout.Session.create(mode='payment', # 他のモードは何がある?

line_items=[{'price': price.id, 'quantity': 1}],

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a100gzzSnVxiOBse34iThOdq...

シンプルそうでしょう?そうです、パラメータが何であるかを知っていれば。しかし、もし私がこれらの記憶を全く持っていない奇妙な人物なら、ドキュメントストリングや実装の詳細を読むためにソースコードを確認しに行く必要があります。よし、それを実行しましょう!チェックアウトセッションを作成するための実際のソースコードは以下の通りです:

@classmethod

def create(cls, **params: Unpack["Session.CreateParams"]) -> "Session":

"""

チェックアウトセッションオブジェクトを作成します。

"""

return cast(

"Session",

cls._static_request(

"post",

cls.class_url(),

params=params,

),

)

まあひどい…支払い処理をアプリに統合するタイミングになると、この瞬間が何度も何度も繰り返されました。私がたどり着いた唯一の解決策は、彼らのウェブサイトに行って実際の API リファレンスドキュメントを確認することでした。もし興味があれば、これらのドキュメントがどのようなものかをご紹介します:

image
image

そのようなドキュメントは、私の目を潤ませるほど美しいものです。ご自身でもご覧になりたい場合は、以下のリンクからアクセスできます。また、他のドキュメントもすべて紹介していますので、非常に書き込まれており、強くお勧めします。

しかし、これらのドキュメントへの頻繁なアクセスは、多くのコンテキストスイッチングを引き起こしました。これは開発者にとって最悪の敵であり、Stripe が開発者に提供するさまざまな方法や機能を探索する際にも、必ずしも優れた体験とは言えません。

私のチームメイトが、支払い機能を持つアプリをリリースしたいたびにこの経験をしなければならないとは思いたくありません。また、あなた、読者の皆様も、そうしてほしくありません。それは楽しいものではありません。数分で終わるはずの作業が、午後の時間を無駄にしてしまうのです。そこで私は、以前同僚だったアイザック(Answer 社の here に所属)が好んで呼ぶ「怒り駆動型開発(Rage-Driven Development: RDD)」を実装し、FastStripe を構築することを決意しました。それは、あなたが本当に受け取るべき Stripe の体験です。

FastStripe

上記の機能を FastStripe で実装するとどうなるか見てみましょう:

from faststripe.core import StripeApi

sapi = StripeApi('your-key-here')

checkout = sapi.one_time_payment(product_name='Digital Course', amount_cents=49_99,

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1u6skiy313rnW2pWwcPhqK5...

単一のメソッド呼び出しにより、内部では製品の作成または既存の製品の検索が行われ、価格の設定とデフォルト値を適切に設定したチェックアウトセッションが作成されます。さらに、より多くの制御権限を望む場合は、FastStripe によってフル機能の Stripe API にアクセス可能となり、おそらく今後一切使用することのないような特殊な API も利用できます(ちなみに、Stripe には気候変動対策製品専用の API が存在するってご存知ですか?このプロジェクトに取り組むまで私は知らなかったのですが、脳のその部分を何か有益な情報で埋めたいと強く願っています。しかし残念ながら…)。また、適切な IDE サポートも追加されているため、美しいタブ補完機能を利用できます。各パラメータを説明するドキュストリング(docstrings)も用意されており、より長く快適な開発環境で作業を進めることができます:

def one_time_payment(

self:StripeApi, product_name, amount_cents,

success_url, cancel_url, currency='usd', quantity=1, **kw):

'Create a simple one-time payment checkout'

_, price = self.priced_product(product_name, amount_cents, currency)

return self.checkout.sessions_post(

mode='payment', line_items=[dict(price=price.id, quantity=quantity)],

automatic_tax={'enabled': True}, success_url=success_url, cancel_url=cancel_url, **kw)

うさぎの穴へと潜る

もしあなたがまだここにおられるなら、あなたはレッドピル(真実の薬)を飲み、私が導く FastStripe の構築プロセスといううさぎの穴へとついてきてくれたと仮定します。では始めましょう!

これがすべてを可能にした要因について話しましょう。Stripe は、魂に祝福され、彼らの API 全体のための本当に美しい OpenAPI スペックを公開しました。さて、もしあなたが OpenAPI スペックに詳しくないなら、それは API と対話する方法の青写真のようなものです。これはすべてのエンドポイント、すべてのパラメータ、そして何をするものかや何を提供すべきかを説明する、それなりに人間に優しい記述までを含んでいます。そして Stripe のものは特に徹底しています。

さらに素晴らしいのは、これらのスペックが JSON または YAML で書かれているため、非常に簡単に解析できることです。数年前、私の CEO であるジェレミー・ハワードとハメル・フサインは、GitHub API 用の動的に Python SDK を生成するためにこれを行いました。それが ghapi です。

ghapi は GitHub API の全体を 100% 常に最新の状態に保ちます。OpenAPI スペックを Python 的な API に自動的に変換するため、ghapi は GitHub API の最新の変更点と常に同期されています。さらに、これがすべて動的に行われるため、パッケージ全体のサイズはわずか 35kB です!

そして私は考えました、もし私が Stripe に対して同じことができるなら、どんなに素晴らしい世界だろうかと。カーテンの裏側にあるコードについて少し注目しましょう。FastStripe はまず、Stripe の OpenAPI スペックのスナップショットを取得し、エンドポイント用の Python ファイルを作成することから始まります。このファイルは、そのスペックをよりクリーンな形式に変換します。この形式は、API へのパス、使用する HTTP メソッド(HTTP verb)、要約(これはドキュストリングの作成に使用されます)、そしてこのパスに関連するパラメータを表しています:

2025.05.28 バージョンの Stripe OpenAPI スペックから生成

eps = [

{

'path': '/v1/customers',

'verb': 'post',

'summary': '顧客を作成する',

'params': [

{'name': 'email', 'description': "顧客のメールアドレス"},

{'name': 'name', 'description': "顧客の氏名"},

# ... 20 以上の説明付きパラメータが続きます

]

},

# ... さらに数百のエンドポイントが続きます

]

次に、これらのエンドポイント記述を取得し、クラスの実行可能メソッド(__call__)のシグネチャとドキュストリングをオーバーライドする Python クラスを自動的に生成します。これにより、IDE 内で快適なタブ補完が可能になり、各パラメータや各エンドポイントが何を行うものか、また各パラメータが何を表すかを容易に確認できます。GhApi と同様に、Jupyter 環境で sapi.checkout のようなコマンドを実行すると、チェックアウトリソース下で実行可能なすべての操作が表示されます:

sapi.checkout

  • checkout.sessions_get(created: 'str', customer: 'str', customer_details: 'str', ending_before: 'str', expand: 'str', limit: 'str', payment_intent: 'str', payment_link: 'str', starting_after: 'str', status: 'str', subscription: 'str'): すべてのチェックアウトセッションを一覧表示
  • checkout.sessions_session_get(session, expand: 'str'): チェックアウトセッションを取得
  • checkout.sessions_session_post(session, collected_information: dict = None, expand: list = None, metadata: object = None, shipping_options: object = None): チェックアウトセッションを更新

...

または、ルート sapi クラスに対して同じ操作を行うことで、すべてのリソースを検索することもできます:

sapi

  • account
  • accounts
  • apple
  • application
  • apps

...

これにより、無数の API ドキュメントページを読み込むよりもはるかに簡単に Stripe API を探索できるようになります。

バージョン管理

FastStripe は、安定性と互換性を確保するために、Stripe の月次 API バージニングに従います。エンドポイントの変更時に既存のコードを壊す可能性がある最新のバージョンを自動的に使用するのではなく、FastStripe のリリースを特定の Stripe API バージョンに固定しています。例えば、FastStripe バージョン 2025.06.30.0 は、2025 年 6 月 30 日時点の Stripe API バージョンに対応しています。sapi.one_time_payment() のような新しい高レベルの利便性メソッドを追加した際に最終数字が増加しますが、最初の 3 つの数字は常に Stripe の API バージョンと一致します。

ヘルパー関数

でも、待ってください!さらにあります!FastStripe は OpenAPI 仕様の素晴らしさのおかげで、Stripe API の全体をサポートしています。ただし、より一般的な成功シナリオを合理化するために、いくつかのヘルパー関数も追加しています。sapi.one_time_payment() がその一例です。実は、イントロダクションでバニラ Stripe と FastStripe のコードの違いを示した際に、少し嘘をついてしまいました。より正確な Stripe 版は以下のようになります。

ステップ 1: プロダクトの作成または検索

products = stripe.Product.list(limit=100)

product = next((p for p in products if p.name == 'Digital Course'), None)

if not product:

product = stripe.Product.create(name='Digital Course')

100 件を超えるプロダクトがある場合のページネーション処理

pass

ステップ 2: プライスの作成または検索

prices = stripe.Price.list(product=product.id, limit=100)

price = next((p for p in prices if p.unit_amount == 4999), None)

if not price:

price = stripe.Price.create(

product=product.id,

unit_amount=4999,

currency='usd'

)

より詳細なページネーション処理

ステップ 3: チェックアウトセッションの作成

checkout = stripe.checkout.Session.create(

mode='payment',

line_items=[{'price': price.id, 'quantity': 1}],

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel'

)

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1y7FuflPm1o3jzOojiGpMHy...

FastStripe のバージョンは、バニラ版の Stripe が約 25 行(コメントを除く)のコードを要するのに対し、わずか 6 行のコードで同じことを実現しました。内部では、FastStripe が提供する priced_product や find_product などの他のヘルパー関数を使用して、ワンタイム支払い用の製品と関連価格を自動的に検索または作成します。サブスクリプションについても同様のヘルパー関数が用意されています:

checkout = sapi.subscription(

product_name='Pro Plan', amount_cents=19_99,

success_url='http://localhost:5001/welcome',

cancel_url='http://localhost:5001/pricing',

customer_email='joe@example.com'

)

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1r4kjOWpmM2OKicG7dF5t1e...

これもまた、FastStripe では 9 行で済むところを、バニラ版では約 25 行のコードが必要だったものです。

ページネーション

多くの REST API と同様に、Stripe アカウント下に作成した製品などのリソースを取得するには、ページネーション(Pagination)に対応する必要があります。Stripe の API は、1 つのリクエストごとに返される結果数を制限しており(例:10 件、25 件、100 件)、これは limit パラメータによって制御されます。実際には結果数がこれを超えることが多いため、次のデータチャンクを取得するために、starting_after や ending_before といったページネーションパラメータを使用して複数のリクエストを行う必要があります。

バニラの Stripe SDK は、これをカーソルベースのページネーションシステムとして公開しています。実際には、すべての製品、顧客、または請求書を取得したい場合、結果を手動でループして繰り返しリクエストを行う必要があります。

products = []

starting_after = None

while True:

resp = stripe.Product.list(limit=100, starting_after=starting_after)

products.extend(resp.data)

if not resp.has_more:

break

starting_after = resp.data[-1].id

break

len(products), products[0].keys()

(100,

dict_keys(['id', 'object', 'active', 'attributes', 'created', 'default_price', 'description', 'images', 'livemode', 'marketing_features', 'metadata', 'name', 'package_dimensions', 'shippable', 'statement_descriptor', 'tax_code', 'type', 'unit_label', 'updated', 'url']))

FastStripe は、すべての結果を自動的に取得するための簡単な方法を提供します。ghapi と同様に、FastStripe には paged 関数があり、これにより任意の Stripe ページネーションエンドポイントを、反復処理可能な Python ジェネレーターに変換します。

from faststripe.page import *

for p in paged(sapi.customers.get, limit=2):

print(len(p.data), p.data[0].keys())

break

2 dict_keys(['id', 'object', 'address', 'balance', 'created', 'currency', 'default_source', 'delinquent', 'description', 'discount', 'email', 'invoice_prefix', 'invoice_settings', 'livemode', 'metadata', 'name', 'next_invoice_sequence', 'phone', 'preferred_locales', 'shipping', 'tax_exempt', 'test_clock'])

また、ページ化されたデータも扱えるようになっています。これにより、すべてのページのアイテムをリスト形式で取得できます:

prods = pages(sapi.products.get, limit=100)

len(prods), prods[0].keys()

(658,

dict_keys(['id', 'object', 'active', 'attributes', 'created', 'default_price', 'description', 'images', 'livemode', 'marketing_features', 'metadata', 'name', 'package_dimensions', 'shippable', 'statement_descriptor', 'tax_code', 'type', 'unit_label', 'updated', 'url']))

FastStripe の始め方

もし、これまでの説明が興味深く、実際に試してみたいとお考えなら、以下の手順に従ってください。

  1. Stripe のセットアップ

Stripe アカウントを作成する

Stripe ダッシュボードにアクセスする

API キーセクションから「Secret key」を取得してください(開発用にはテストキーを使用してください)

  1. FastStripe のセットアップ

pip install faststripe

API を初期化します:

from faststripe.core import StripeApi

sapi = StripeApi('your-key-here')

チェックアウトセッションを作成します(ワンタイム決済の場合):

checkout = sapi.one_time_payment(product_name='Digital Course', amount_cents=49_99,

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1PxMDnqAbBYoqeNgdYyVxST...

または、サブスクリプションの場合:

checkout = sapi.subscription(

product_name='Pro Plan', amount_cents=19_99,

success_url='http://localhost:5001/welcome',

cancel_url='http://localhost:5001/pricing',

customer_email='joe@example.com'

)

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1oTHsHFpEdQWIwHVb5Ghav0...

次のステップ

より多くの例については、完全なドキュメントをご覧ください。

機能のリクエストや問題の報告については、GitHub でのディスカッションに参加してください。

FastStripe はオープンソースであり、皆様のフィードバックを心から歓迎します。1 つのアプリを開発している方でも、1000 のアプリを構築している方でも、Stripe の統合が可能な限りスムーズになるよう努めています。

原文を表示

TL;DR

tldr: I got frustrated with the developer experience I was getting with the Stripe SDK and decided to create, in my opinion, a better one called FastStripe. FastStripe supports the full Stripe API thanks to the awesome OpenAPI spec that Stripe released, but it makes it cleaner, organizes it better, and integrates well with your IDE so that you get nice tab completion on your parameters. You get clean docstrings that explain what the function does and what each parameter does. We also add helper functions and make doing things like creating one-time payments be done in 6 lines of code, whereas with the official SDK, it’s roughly 25. Or setting up a recurring subscription—FastStripe gets it done in 9 lines of code where the equivalent in the official SDK is roughly 25 lines.

It is out and about. It has been powering our own internal apps for almost a month now without any issues, all the while reducing their complexity. You can start using it by running pip install faststripe and creating your very first one-time payment link:

from faststripe.core import StripeApi

sapi = StripeApi('your-key-here')

checkout = sapi.one_time_payment(product_name='Digital Course', amount_cents=49_99,

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1gQnoO5ezm5yFB47GZNWO6I...

We also continually update FastStripe for every new version of the Stripe API.

The Stripe Experience You Deserve

Stop me if this sounds familiar: You want to take people’s money, and you want to make sure you can take it super easily. Like candy from a baby easy. And, yeah, yeah, yeah, of course, you want to, in exchange for that money, provide some service or product that the person is willing to exchange their money for. This used to be a nightmare to do and for some companies; it can still kind of feel like a nightmare (Cough, cough, Google)

image
image

Stripe makes much of this process pretty easy, but by golly, trying to use their SDK over the last eight months has been a journey, and it’s been a long one. So long and bumpy that I realized early on that this just wasn’t going to cut it. Let me show you what I mean. Here’s what accepting payments typically looks like:

import stripe

Step 0: Set up Stripe API key

stripe.api_key = 'your-api-key'

Step 1: Create a product (hope you remember the parameters)

product = stripe.Product.create(name='Digital Course')

Step 2: Create a price (what parameters does this take again?)

price = stripe.Price.create(product=product.id, unit_amount=4999, # Wait, is this in cents or dollars?

currency='usd')

Step 3: Create checkout session (time to hunt through docs)

checkout = stripe.checkout.Session.create(mode='payment', # What other modes are there?

line_items=[{'price': price.id, 'quantity': 1}],

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a100gzzSnVxiOBse34iThOdq...

Looks simple enough, right? Well, when you know what the parameters are, it is. But if I’m some weirdo who doesn’t actually have any of these memories, I need to go look at the source code to read the docstring and implementation details. Great, let’s do that! Here’s the actual source code for creating a checkout session:

@classmethod

def create(cls, **params: Unpack["Session.CreateParams"]) -> "Session":

"""

Creates a Checkout Session object.

"""

return cast(

"Session",

cls._static_request(

"post",

cls.class_url(),

params=params,

),

)

Well shit… I experienced this moment again and again and again when it came time to integrate payment processing into my apps. The only solution that I could find was to go to their website and look at the actual API reference docs. Here’s what those docks look like in case you’re interested:

image
image

Docs like that bring a tear to my eye. It’s just so beautiful. Here’s a link to it as well if you want to see it for yourself, along with the rest of the docs, which I highly recommend, as they’re really well written. However, these trips to the docs caused a lot of context switching, which is a developer’s worst friend, and it’s also not a great experience for being able to explore different ways and features that Stripe offers to developers.

I don’t want my teammates to have to experience this every time they want to launch an app that takes payments. I don’t want you, the reader, to have to do this either. It’s not fun. It kills an afternoon when it should take a few minutes. And so, I decided to implement what one of my previous colleagues, Isaac, here at Answer likes to call rage-driven development (RDD) and build FastStripe: the Stripe experience you deserve.

FastStripe

Let’s see what it looks like to implement the above in FastStripe:

from faststripe.core import StripeApi

sapi = StripeApi('your-key-here')

checkout = sapi.one_time_payment(product_name='Digital Course', amount_cents=49_99,

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1u6skiy313rnW2pWwcPhqK5...

A single method call, which under the hood handles creating the product or finding an existing product, sets up the price and creates your checkout session with sensible defaults. And if you want more control, FastStripe gives you access to the full Stripe API, even those esoteric ones that you’ll probably never use (By the way, did you know that Stripe has an API specifically for Climate products?! I didn’t until working on this project and really wish I could fill that part of my brain with something useful. Alas…). It also adds proper IDE support, so you have nice tab completion. You also have nice docstrings that explain each parameter, letting you stay in your happy place for longer:

def one_time_payment(

self:StripeApi, product_name, amount_cents,

success_url, cancel_url, currency='usd', quantity=1, **kw):

'Create a simple one-time payment checkout'

_, price = self.priced_product(product_name, amount_cents, currency)

return self.checkout.sessions_post(

mode='payment', line_items=[dict(price=price.id, quantity=quantity)],

automatic_tax={'enabled': True}, success_url=success_url, cancel_url=cancel_url, **kw)

Down the Rabbit Hole We Go

Well if you are still here, I’ll assume you took the red pill and are following me down the rabbit hole of how I built FastStripe. Let’s begin!

Let’s talk about what made this all possible. Stripe, bless their souls, went ahead and published a truly beautiful OpenAPI spec for their entire API. Now, if you’re not familiar, OpenAPI specs are like the blueprint for how to talk to an API. They describe every endpoint, every parameter, and even decent human-friendly descriptions for what things do and what you need to provide. And Stripe’s is exceptionally thorough.

What’s even cooler is that these specs are really easily parsed since they are written in either JSON or YAML. Years back, my CEO Jeremy Howard and Hamel Husain did this to dynamically generate a python SDK for the GitHub API called ghapi.

ghapi provides 100% always-updated coverage of the entire GitHub API. Because we automatically convert the OpenAPI spec to a Pythonic API, ghapi is always up to date with the latest changes to GitHub APIs. Furthermore, because this is all done dynamically, the entire package is only 35kB in size!

And I thought to myself, what a wonderful world it would be if I could do the same for Stripe. Let’s pay a little bit of attention to the man code behind the curtain. FastStripe first works by taking a snapshot of Stripe’s OpenAPI specification and creating an endpoints Python file, which converts that spec into a cleaner form. This form represents the path to the API, what HTTP verb to use, its summary (which will be used for creating the docstring), and the parameters associated with this path:

Generated from Stripe's OpenAPI spec for version 2025.05.28

eps = [

{

'path': '/v1/customers',

'verb': 'post',

'summary': 'Create a customer',

'params': [

{'name': 'email', 'description': "Customer's email address"},

{'name': 'name', 'description': "Customer's full name"},

# ... 20+ more parameters with descriptions

]

},

# ... hundreds more endpoints

]

We then take these endpoint descriptions and use them to automatically generate Python classes where we override the signature and docstring of the class’s __call__ method. This means in your IDE you have nice tab completions and can easily view what each parameter does, which each endpoint does, and what each parameter is. And similar to GhApi, you can run things like sapi.checkout in a Jupyter environment and it will show all the available operations you can do under the checkout resource:

sapi.checkout

  • checkout.sessions_get(created: 'str', customer: 'str', customer_details: 'str', ending_before: 'str', expand: 'str', limit: 'str', payment_intent: 'str', payment_link: 'str', starting_after: 'str', status: 'str', subscription: 'str'): List all Checkout Sessions
  • checkout.sessions_session_get(session, expand: 'str'): Retrieve a Checkout Session
  • checkout.sessions_session_post(session, collected_information: dict = None, expand: list = None, metadata: object = None, shipping_options: object = None): Update a Checkout Session

...

Or explore all the resources by doing the same for the root sapi class:

sapi

  • account
  • accounts
  • apple
  • application
  • apps

...

This makes exploring the Stripe API so much easier than reading through countless API doc pages.

Versioning

FastStripe follows Stripe’s monthly API versioning to ensure stability and compatibility. Rather than automatically using the latest version (which could break existing code when endpoints change), we pin FastStripe releases to specific Stripe API versions. For example, FastStripe version 2025.06.30.0 corresponds to Stripe’s API version from June 30th, 2025. The final number increments when we add new high-level convenience methods like sapi.one_time_payment(), but the first three numbers always match Stripe’s API version.

Helper Functions

But wait, there’s more! FastStripe supports, thanks to the awesomeness of the OpenAPI spec, the entire Stripe API. However, we also add some helper functions to streamline some of the more common happy paths. sapi.one_time_payment() is one of these helper functions. In fact, I lied a bit in the intro when I showed the difference in code between doing it in vanilla Stripe and FastStripe. The more accurate Stripe version would be this:

Step 1: Create or find a product

products = stripe.Product.list(limit=100)

product = next((p for p in products if p.name == 'Digital Course'), None)

if not product:

product = stripe.Product.create(name='Digital Course')

Handle pagination if you have >100 products

pass

Step 2: Create or find a price

prices = stripe.Price.list(product=product.id, limit=100)

price = next((p for p in prices if p.unit_amount == 4999), None)

if not price:

price = stripe.Price.create(

product=product.id,

unit_amount=4999,

currency='usd'

)

More pagination handling

Step 3: Create checkout session

checkout = stripe.checkout.Session.create(

mode='payment',

line_items=[{'price': price.id, 'quantity': 1}],

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel'

)

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1y7FuflPm1o3jzOojiGpMHy...

The FastStripe version accomplished the same in 6 lines of code compared to the roughly 25 lines (if you omit the comments) of code that vanilla Stripe takes. Under the hood, the one-time payment function in FastStripe will either find or create the product with an associated price for your one-time payment automatically, using the other helper functions that FastStripe provides, like priced_product and find_product. We also got a similar helper function for subscriptions:

checkout = sapi.subscription(

product_name='Pro Plan', amount_cents=19_99,

success_url='http://localhost:5001/welcome',

cancel_url='http://localhost:5001/pricing',

customer_email='joe@example.com'

)

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1r4kjOWpmM2OKicG7dF5t1e...

Which again would have been roughly 25 lines of code compared to FastStripe’s 9.

Pagination

Like many REST APIs, getting a resource, such as the products that you’ve created under your Stripe account, requires you to deal with pagination. Stripe’s API will only return a limited number of results per request (e.g., 10, 25, 100), controlled by a limit parameter. Frequently, you have more results than this, so you need to make multiple requests using pagination parameters such as starting_after or ending_before to fetch the next chunk of data.

The vanilla Stripe SDK exposes this as a cursor-based pagination system. In practice, this means if you want to get all products, customers, or invoices, you have to loop through the results manually, making repeated requests:

products = []

starting_after = None

while True:

resp = stripe.Product.list(limit=100, starting_after=starting_after)

products.extend(resp.data)

if not resp.has_more:

break

starting_after = resp.data[-1].id

break

len(products), products[0].keys()

(100,

dict_keys(['id', 'object', 'active', 'attributes', 'created', 'default_price', 'description', 'images', 'livemode', 'marketing_features', 'metadata', 'name', 'package_dimensions', 'shippable', 'statement_descriptor', 'tax_code', 'type', 'unit_label', 'updated', 'url']))

FastStripe offers an easy way to automatically fetch all results. Similar to ghapi, FastStripe has a paged function which turns any Stripe pagination endpoint into a Python generator that you can iterate through:

from faststripe.page import *

for p in paged(sapi.customers.get, limit=2):

print(len(p.data), p.data[0].keys())

break

2 dict_keys(['id', 'object', 'address', 'balance', 'created', 'currency', 'default_source', 'delinquent', 'description', 'discount', 'email', 'invoice_prefix', 'invoice_settings', 'livemode', 'metadata', 'name', 'next_invoice_sequence', 'phone', 'preferred_locales', 'shipping', 'tax_exempt', 'test_clock'])

We also have pages, which will return all items from all the pages as a list:

prods = pages(sapi.products.get, limit=100)

len(prods), prods[0].keys()

(658,

dict_keys(['id', 'object', 'active', 'attributes', 'created', 'default_price', 'description', 'images', 'livemode', 'marketing_features', 'metadata', 'name', 'package_dimensions', 'shippable', 'statement_descriptor', 'tax_code', 'type', 'unit_label', 'updated', 'url']))

Getting Started with FastStripe

So, if all of this sounded interesting and you’d like to try it for yourself, here is how:

  1. Stripe Setup

Create a Stripe account

Go to the Stripe Dashboard

Get your “Secret key” from the API keys section (use test keys for development)

  1. FastStripe Setup

pip install faststripe

Initialize your API:

from faststripe.core import StripeApi

sapi = StripeApi('your-key-here')

Make a checkout sesssion (one-time payment):

checkout = sapi.one_time_payment(product_name='Digital Course', amount_cents=49_99,

success_url='http://localhost:5001/success',

cancel_url='http://localhost:5001/cancel')

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1PxMDnqAbBYoqeNgdYyVxST...

or subscription:

checkout = sapi.subscription(

product_name='Pro Plan', amount_cents=19_99,

success_url='http://localhost:5001/welcome',

cancel_url='http://localhost:5001/pricing',

customer_email='joe@example.com'

)

print(checkout.url[:64] + "...")

https://billing.answer.ai/c/pay/cs_test_a1oTHsHFpEdQWIwHVb5Ghav0...

Next Steps

Check out the full documentation for more examples

Join the discussion on GitHub to request features or report issues

FastStripe is open source and we’d love your feedback. Whether you’re building one app or a thousand, we want to make Stripe integrations as frictionless as possible.

この記事をシェア

関連記事

Cloudflare Blog★42026年6月4日 21:59

Vite 開発元 VoidZero が Cloudflare に参画

Vite や Vitest を開発する企業「VoidZero」がクラウドプロバイダー「Cloudflare」に合流し、同社全従業員も Cloudflare の一員となる。ただし、主要プロジェクトは引き続きオープンソースとして運営される方針を示した。

TLDR AI★42026年5月15日 09:00

Genkit ミドルウェア(10 分読了)

Genkit は、TypeScript や Python など複数の言語に対応し、信頼性の高い AI エージェントアプリケーションを構築するためのフレームワークです。このツールは、生成呼び出しをインターセプトするコンポーザブルフックや、破壊的なツールの実行前に人間が承認を行う機能を提供します。

GitHub Blog★32026年4月29日 03:00

GitHub 初心者向け:Markdown の始め方

GitHub は、このシリーズで Issues や Actions など多様なトピックを扱った後、GitHub で広く使われているマークアップ言語である Markdown の基礎から実践までを解説する。これにより、README の作成や Issue、プルリクエストの書式設定が効率化される。

今日のまとめ

AI日報で今日の重要ニュースをまとめ読み

ニュース一覧に戻る元記事を読む