8000 Are stripe objects dicts? · Issue #494 · stripe/stripe-python · GitHub
[go: up one dir, main page]

Skip to content

Are stripe objects dicts? #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oTree-org opened this issue Nov 16, 2018 · 3 comments
Closed

Are stripe objects dicts? #494

oTree-org opened this issue Nov 16, 2018 · 3 comments

Comments

@oTree-org
Copy link

When reading the docs about subscriptions, customers, etc., I sometimes see attribute notation, like

subscription.tax_percent = 10

And sometimes see dict notation, like subscription['items']['data'][0].id, and sometimes see a mix (e.g. in the previous example why not use ['id'] at the end?)

What is the difference between the two? I was wondering if I could use dict notation all the way, like subscription['items']['data'][0]['id']. That means in my tests using unittest.mock I could patch the return values of create, retrieve, etc. using simple dict literals.

(By the way the docs have examples on how to use stripe-python, but I can't find any general explanation of how stripe-python is works, e.g. what data types it uses and how those map to JSON responses.)

Thanks!

@jleclanche
Copy link
Contributor

stripe-python uses a custom dict object which supports lua/js-like behaviour of getting/setting keys through python attributes.

In dj-stripe we try to treat them purely as dict. It's more consistent.

@oTree-org
Copy link
Author

Thanks!

@ob-stripe
Copy link
Contributor

@oTree-org @jleclanche is correct, stripe-python's objects are indeed dicts with some additional magic to support dot notation.

The reason the documentation uses the [] notation when accessing items is that, because the objects are dicts, subscription.items returns the items() function rather than the value associated with the 'items' key. So in this specific instance, using the dict notation is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0