Better document how to reconstruct `data` object of Webhook events

Open
#1,841 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
54/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
documentation

Research direction

Start with the linked Webhooks documentation and the stripe.Subscription.construct_from() entry point. Confirm whether event.data.object.to_dict() is required and how the key parameter affects reconstructed objects, then document the recommended pattern and add a clear docstring for construct_from().

Written by the indexing model from the issue text.

Description

feature-request
Is your feature request related to a problem? Please describe.

The documentation currently recommends using stripe.Event.construct_from() to reconstruct the event object, and then access event.data.object to use the actual event data.

However, event.data.object is untyped (UntypedStripeObject[Any]). We currently do:

# Example to reconstruct `Subscription` object, but same applies for any object:
sub = stripe.Subscription.construct_from(
    event.data.object.to_dict(),
    key=None,  # The API key (required)
)

It would be nice if this was explicitly documented (in https://docs.stripe.com/webhooks): is it the expected way of reconstructing the object? do I need to call to_dict()? Also if this is the expected way, construct_from() would benefit from a proper docstring (I first got confused by the required key parameter. It does make sense to have it required, because an implicit None will mean you can't make operations from this object directly, which would be surprising for some users).

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Dominant language
Python
Stars
2k
Forks
539
Avg merge
2d 7h
Merged PRs (30d)
26

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stripe/stripe-python

All issues in stripe/stripe-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.