Skip to content

Commit

Permalink
Clean up examples (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
jar-stripe authored Oct 9, 2024
1 parent 9ad9bfa commit 1e8ee47
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
11 changes: 8 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
From the examples folder, run:
`PYTHONPATH=../ python your_example.py`

e.g.

`PYTHONPATH=../ python thinevent_webhook_handler.py`

## Adding a new example

1. Clone new_example.py
1. Clone example_template.py
2. Implement your example
3. Run it (as per above)
4. 👍
3. Fill out the file comment. Include a description and key steps that are being demonstrated.
4. Run it (as per above)
5. 👍
22 changes: 22 additions & 0 deletions examples/example_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
example_template.py - This is a template for defining new examples. It is not intended to be used directly.
<describe what this example does>
In this example, we:
- <key step 1>
- <key step 2
- ...
<describe assumptions about the user's stripe account, environment, or configuration;
or things to watch out for when running>
"""

import stripe

# Set your API key here
api_key = "{{API_KEY}}"

print("Hello world")
# client = stripe.StripeClient(api_key)
# client.v2....
12 changes: 12 additions & 0 deletions examples/meter_event_stream.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
"""
meter_event_stream.py - use the high-throughput meter event stream to report create billing meter events.
In this example, we:
- create a meter event session and store the session's authentication token
- define an event with a payload
- use the meter_event_stream service accessor in StripeClient to create an event stream that reports this event
This example expects a billing meter with an event_name of 'alpaca_ai_tokens'. If you have
a different meter event name, you can change it before running this example.
"""

from datetime import datetime, timezone
import stripe

Expand Down
8 changes: 0 additions & 8 deletions examples/new_example.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
"""
thinevent_webhook_handler.py - receive and process thin events like the
v1.billing.meter.error_report_triggered event.
In this example, we:
- create a StripeClient called client
- use client.parse_thin_event to parse the received thin event webhook body
- call client.v2.core.events.retrieve to retrieve the full event object
- if it is a V1BillingMeterErrorReportTriggeredEvent event type, call
event.fetchRelatedObject to retrieve the Billing Meter object associated
with the event.
"""

import os
from stripe import StripeClient
from stripe.events import V1BillingMeterErrorReportTriggeredEvent
Expand Down

0 comments on commit 1e8ee47

Please sign in to comment.