Name | stytch JSON |
Version |
11.10.0
JSON |
| download |
home_page | None |
Summary | Stytch python client |
upload_time | 2024-11-14 18:16:44 |
maintainer | None |
docs_url | None |
author | Stytch |
requires_python | >=3.8 |
license | MIT |
keywords |
stytch
user
authentication
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Stytch Python Library
The Stytch Python library makes it easy to use the Stytch user infrastructure API in Python applications.
It pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/vanilla-js) or your own custom authentication flow.
## Requirements
The Stytch Python library supports Python 3.8+
## Installation
```
pip install stytch
```
## Usage
You can find your API credentials in the [Stytch Dashboard](https://stytch.com/dashboard/api-keys).
This client library supports all Stytch's live products:
## B2C
- [x] [Email Magic Links](https://stytch.com/docs/api/send-by-email)
- [x] [Embeddable Magic Links](https://stytch.com/docs/guides/magic-links/embeddable-magic-links/api)
- [x] [OAuth logins](https://stytch.com/docs/guides/oauth/idp-overview)
- [x] [SMS passcodes](https://stytch.com/docs/api/send-otp-by-sms)
- [x] [WhatsApp passcodes](https://stytch.com/docs/api/whatsapp-send)
- [x] [Email passcodes](https://stytch.com/docs/api/send-otp-by-email)
- [x] [Session Management](https://stytch.com/docs/guides/sessions/using-sessions)
- [x] [WebAuthn](https://stytch.com/docs/guides/webauthn/api)
- [x] [Time-based one-time passcodes (TOTPs)](https://stytch.com/docs/guides/totp/api)
- [x] [Crypto wallets](https://stytch.com/docs/guides/web3/api)
- [x] [Passwords](https://stytch.com/docs/guides/passwords/api)
## B2B
- [x] [Organizations](https://stytch.com/docs/b2b/api/organization-object)
- [x] [Members](https://stytch.com/docs/b2b/api/member-object)
- [x] [Email Magic Links](https://stytch.com/docs/b2b/api/send-login-signup-email)
- [x] [OAuth logins](https://stytch.com/docs/b2b/api/oauth-google-start)
- [x] [Session Management](https://stytch.com/docs/b2b/api/session-object)
- [x] [Single-Sign On](https://stytch.com/docs/b2b/api/sso-authenticate-start)
- [x] [Discovery](https://stytch.com/docs/b2b/api/discovered-organization-object)
- [x] [Passwords](https://stytch.com/docs/b2b/api/passwords-authenticate)
### Example B2C usage
Create an API client:
```python
import stytch
client = stytch.Client(
project_id="project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret="secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
)
```
Send a magic link by email:
```python
login_or_create_resp = client.magic_links.email.login_or_create(
email="sandbox@stytch.com",
login_magic_link_url="https://example.com/authenticate",
signup_magic_link_url="https://example.com/authenticate",
)
# Responses are fully-typed `pydantic` objects
print(login_or_create_resp)
```
Authenticate the token from the magic link:
```python
auth_resp = client.magic_links.authenticate(
token="DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=",
)
print(auth_resp)
```
## Async support
Every endpoint supports an `async` version which you can use by appending `_async` to the method name. You can use the
same `Client` object for `sync` and `async` methods. The above example of sending and authenticating an magic link can
be rewritten as:
```python
login_or_create_resp = await client.magic_links.email.login_or_create_async(
email="sandbox@stytch.com",
login_magic_link_url="https://example.com/authenticate",
signup_magic_link_url="https://example.com/authenticate",
)
print(login_or_create_resp)
auth_resp = await client.magic_links.authenticate(
token="DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=",
)
print(resp)
```
### Example B2B usage
Create an API client:
Python:
```python
import stytch
client = stytch.B2BClient(
project_id="project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret="secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
)
```
Create an organization
```python
response = client.organizations.create(
organization_name="Acme Co",
organization_slug="acme-co",
email_allowed_domains=["acme.co"]
)
```
Log the first user into the organization
```python
response = client.magic_links.email.login_or_signup(
organization_id="ORGANIZATION_ID_FROM_RESPONSE",
email_address="admin@acme.co",
login_redirect_url="https://example.com/authenticate",
signup_redirect_url="https://example.com/authenticate"
)
```
## Handling Errors
Structured errors from the Stytch API will raise `StytchError` exceptions. You can view the details of the error through
the `.details` property of the `StytchError` exception.
```python
from stytch.core.response_base import StytchError
try:
auth_resp = await client.magic_links.authenticate_async(token="token")
except StytchError as error:
# Handle Stytch errors here
if error.details.error_type == "invalid_token":
print("Whoops! Try again?")
except Exception as error:
# Handle other errors here
pass
```
Learn more about errors in the [docs](https://stytch.com/docs/api/errors).
## Documentation
See example requests and responses for all the endpoints in the [Stytch API Reference](https://stytch.com/docs/api).
Follow one of the [integration guides](https://stytch.com/docs/home#guides) or start with one of our [example apps](https://stytch.com/docs/home#example-apps).
## Support
If you've found a bug, [open an issue](https://github.com/stytchauth/stytch-python/issues/new)!
If you have questions or want help troubleshooting, join us in [Slack](https://stytch.com/docs/resources/support/overview) or email support@stytch.com.
If you've found a security vulnerability, please follow our [responsible disclosure instructions](https://stytch.com/docs/resources/security-and-trust/security#:~:text=Responsible%20disclosure%20program).
## Development
See [DEVELOPMENT.md](DEVELOPMENT.md)
## Code of Conduct
Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
Raw data
{
"_id": null,
"home_page": null,
"name": "stytch",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "stytch, user, authentication",
"author": "Stytch",
"author_email": "hello@stytch.com",
"download_url": "https://files.pythonhosted.org/packages/30/3f/a13925ca3e43f7fb076496e6ce143a7376d62e0ecfadbaa15aeaefc5345e/stytch-11.10.0.tar.gz",
"platform": null,
"description": "# Stytch Python Library\n\nThe Stytch Python library makes it easy to use the Stytch user infrastructure API in Python applications.\n\nIt pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/vanilla-js) or your own custom authentication flow.\n\n## Requirements\n\nThe Stytch Python library supports Python 3.8+\n\n## Installation\n\n```\npip install stytch\n```\n\n## Usage\n\nYou can find your API credentials in the [Stytch Dashboard](https://stytch.com/dashboard/api-keys).\n\nThis client library supports all Stytch's live products:\n\n## B2C\n\n- [x] [Email Magic Links](https://stytch.com/docs/api/send-by-email)\n- [x] [Embeddable Magic Links](https://stytch.com/docs/guides/magic-links/embeddable-magic-links/api)\n- [x] [OAuth logins](https://stytch.com/docs/guides/oauth/idp-overview)\n- [x] [SMS passcodes](https://stytch.com/docs/api/send-otp-by-sms)\n- [x] [WhatsApp passcodes](https://stytch.com/docs/api/whatsapp-send)\n- [x] [Email passcodes](https://stytch.com/docs/api/send-otp-by-email)\n- [x] [Session Management](https://stytch.com/docs/guides/sessions/using-sessions)\n- [x] [WebAuthn](https://stytch.com/docs/guides/webauthn/api)\n- [x] [Time-based one-time passcodes (TOTPs)](https://stytch.com/docs/guides/totp/api)\n- [x] [Crypto wallets](https://stytch.com/docs/guides/web3/api)\n- [x] [Passwords](https://stytch.com/docs/guides/passwords/api)\n\n## B2B\n\n- [x] [Organizations](https://stytch.com/docs/b2b/api/organization-object)\n- [x] [Members](https://stytch.com/docs/b2b/api/member-object)\n- [x] [Email Magic Links](https://stytch.com/docs/b2b/api/send-login-signup-email)\n- [x] [OAuth logins](https://stytch.com/docs/b2b/api/oauth-google-start)\n- [x] [Session Management](https://stytch.com/docs/b2b/api/session-object)\n- [x] [Single-Sign On](https://stytch.com/docs/b2b/api/sso-authenticate-start)\n- [x] [Discovery](https://stytch.com/docs/b2b/api/discovered-organization-object)\n- [x] [Passwords](https://stytch.com/docs/b2b/api/passwords-authenticate)\n\n### Example B2C usage\n\nCreate an API client:\n\n```python\nimport stytch\n\nclient = stytch.Client(\n project_id=\"project-live-c60c0abe-c25a-4472-a9ed-320c6667d317\",\n secret=\"secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=\",\n)\n```\n\nSend a magic link by email:\n\n```python\nlogin_or_create_resp = client.magic_links.email.login_or_create(\n email=\"sandbox@stytch.com\",\n login_magic_link_url=\"https://example.com/authenticate\",\n signup_magic_link_url=\"https://example.com/authenticate\",\n)\n# Responses are fully-typed `pydantic` objects\nprint(login_or_create_resp)\n```\n\nAuthenticate the token from the magic link:\n\n```python\nauth_resp = client.magic_links.authenticate(\n token=\"DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=\",\n)\nprint(auth_resp)\n```\n\n## Async support\n\nEvery endpoint supports an `async` version which you can use by appending `_async` to the method name. You can use the\nsame `Client` object for `sync` and `async` methods. The above example of sending and authenticating an magic link can\nbe rewritten as:\n\n```python\nlogin_or_create_resp = await client.magic_links.email.login_or_create_async(\n email=\"sandbox@stytch.com\",\n login_magic_link_url=\"https://example.com/authenticate\",\n signup_magic_link_url=\"https://example.com/authenticate\",\n)\nprint(login_or_create_resp)\n\nauth_resp = await client.magic_links.authenticate(\n token=\"DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=\",\n)\nprint(resp)\n```\n\n### Example B2B usage\n\nCreate an API client:\n\nPython:\n\n```python\nimport stytch\n\nclient = stytch.B2BClient(\n project_id=\"project-live-c60c0abe-c25a-4472-a9ed-320c6667d317\",\n secret=\"secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=\",\n)\n```\n\nCreate an organization\n\n```python\nresponse = client.organizations.create(\n organization_name=\"Acme Co\",\n organization_slug=\"acme-co\",\n email_allowed_domains=[\"acme.co\"]\n)\n```\n\nLog the first user into the organization\n\n```python\nresponse = client.magic_links.email.login_or_signup(\n organization_id=\"ORGANIZATION_ID_FROM_RESPONSE\",\n email_address=\"admin@acme.co\",\n login_redirect_url=\"https://example.com/authenticate\",\n signup_redirect_url=\"https://example.com/authenticate\"\n)\n```\n\n## Handling Errors\n\nStructured errors from the Stytch API will raise `StytchError` exceptions. You can view the details of the error through\nthe `.details` property of the `StytchError` exception.\n\n```python\nfrom stytch.core.response_base import StytchError\n\ntry:\n auth_resp = await client.magic_links.authenticate_async(token=\"token\")\nexcept StytchError as error:\n # Handle Stytch errors here\n if error.details.error_type == \"invalid_token\":\n print(\"Whoops! Try again?\")\nexcept Exception as error:\n # Handle other errors here\n pass\n```\n\nLearn more about errors in the [docs](https://stytch.com/docs/api/errors).\n\n## Documentation\n\nSee example requests and responses for all the endpoints in the [Stytch API Reference](https://stytch.com/docs/api).\n\nFollow one of the [integration guides](https://stytch.com/docs/home#guides) or start with one of our [example apps](https://stytch.com/docs/home#example-apps).\n\n## Support\n\nIf you've found a bug, [open an issue](https://github.com/stytchauth/stytch-python/issues/new)!\n\nIf you have questions or want help troubleshooting, join us in [Slack](https://stytch.com/docs/resources/support/overview) or email support@stytch.com.\n\nIf you've found a security vulnerability, please follow our [responsible disclosure instructions](https://stytch.com/docs/resources/security-and-trust/security#:~:text=Responsible%20disclosure%20program).\n\n## Development\n\nSee [DEVELOPMENT.md](DEVELOPMENT.md)\n\n## Code of Conduct\n\nEveryone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Stytch python client",
"version": "11.10.0",
"project_urls": {
"Download": "https://github.com/stytchauth/stytch-python"
},
"split_keywords": [
"stytch",
" user",
" authentication"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "303fa13925ca3e43f7fb076496e6ce143a7376d62e0ecfadbaa15aeaefc5345e",
"md5": "565081443d98dedf7306d692d365f830",
"sha256": "299f13710ebecabf87ff309ddc6233da78bec79e3eba382f1d074b23202b57eb"
},
"downloads": -1,
"filename": "stytch-11.10.0.tar.gz",
"has_sig": false,
"md5_digest": "565081443d98dedf7306d692d365f830",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 126245,
"upload_time": "2024-11-14T18:16:44",
"upload_time_iso_8601": "2024-11-14T18:16:44.945354Z",
"url": "https://files.pythonhosted.org/packages/30/3f/a13925ca3e43f7fb076496e6ce143a7376d62e0ecfadbaa15aeaefc5345e/stytch-11.10.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-14 18:16:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stytchauth",
"github_project": "stytch-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "stytch"
}