Skip to content

Commit bb8e28a

Browse files
committed
Add Python SDK tab to docs
1 parent 92cd746 commit bb8e28a

File tree

12 files changed

+113
-21
lines changed

12 files changed

+113
-21
lines changed

apps/e2e/tests/general/setup-wizard.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ describe("Setup wizard", () => {
1010
});
1111
});
1212
expect(error, `Expected no error to be thrown!\n\n\n\nstdout: ${stdout}\n\n\n\nstderr: ${stderr}`).toBeNull();
13-
}, 120_000);
13+
}, 240_000);
1414
});

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
fern/js.yml
22
fern/next.yml
33
fern/react.yml
4+
fern/python.yml
45
fern/docs/pages-js
56
fern/docs/pages-next
67
fern/docs/pages-react
8+
fern/docs/pages-python

docs/fern/docs-template.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ navigation:
2828
icon: fa-regular fa-circle-question
2929
path: ./docs/pages-{platform}/faq.mdx
3030
- section: Getting Started
31+
platform: js-like
3132
contents:
3233
- page: Installation & Setup
3334
icon: fa-regular fa-download
@@ -46,7 +47,14 @@ navigation:
4647
- page: Going to Production
4748
icon: fa-regular fa-rocket
4849
path: ./docs/pages-{platform}/getting-started/production.mdx
50+
- section: Getting Started
51+
platform: python-like
52+
contents:
53+
- page: Setup
54+
icon: fa-regular fa-download
55+
path: ./docs/pages-{platform}/getting-started/setup.mdx
4956
- section: Concepts
57+
platform: js-like
5058
contents:
5159
- page: The StackApp Object
5260
icon: fa-regular fa-folder-gear
@@ -103,6 +111,7 @@ navigation:
103111
- page: Password Reset
104112
path: ./docs/pages-{platform}/customization/page-examples/password-reset.mdx
105113
- section: Others
114+
platform: js-like
106115
contents:
107116
- page: Supabase Integration
108117
icon: fa-regular fa-bolt
@@ -158,6 +167,7 @@ navigation:
158167
icon: fa-solid fa-square-u
159168
path: ./docs/pages-{platform}/components/stack-theme.mdx
160169
- tab: sdk
170+
platform: js-like
161171
layout:
162172
- page: SDK Overview
163173
icon: fa-regular fa-globe

docs/fern/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ versions:
1919
- display-name: JavaScript SDK
2020
path: js.yml
2121
slug: js
22+
- display-name: Python SDK
23+
path: python.yml
24+
slug: python
2225

2326
navbar-links:
2427
- type: secondary

docs/fern/docs/pages-template/faq.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ subtitle: Frequently asked questions about Stack
66
## Languages & Frameworks
77
<AccordionGroup>
88
<Accordion title="What languages are supported?">
9-
In the frontend, Stack supports TypeScript and JavaScript with Next.js. In the backend, Stack has a flexible [REST API](/rest-api) that can be used with any language or framework.
9+
For frontends, Stack supports TypeScript and JavaScript. For backends, Stack has a flexible [REST API](/rest-api) that can be used with any language or framework.
1010
</Accordion>
1111
<Accordion title="Can I use Stack with other JavaScript frameworks, like Astro or Angular?">
12-
While you can use any backend framework with Stack, the frontend is tightly integrated with Next.js. If you want to use a different frontend framework, you will have to build the integration ourselves with the client endpoints of our [REST API](/rest-api). Some members of our community have started projects to do this, so you may want to join [our Discord](https://discord.stack-auth.com) to coordinate with them.
12+
Yes! You can use our vanilla JavaScript SDK, or, if the framework is React-based, our React SDK.
1313
</Accordion>
1414
<Accordion title="Can I use Stack with the Next.js pages router?">
15-
Only the Next.js app router is currently supported. However, just like any other unsupported framework, you can use the client endpoints of our [REST API](/rest-api) to build your own integration.
15+
Only the Next.js app router is currently officially supported, although some members of the community have successfully used the React or vanilla JavaScript SDKs with the pages router.
1616
</Accordion>
1717
</AccordionGroup>
1818

1919
## Product
2020
<AccordionGroup>
21-
<Accordion title="How do you compare to <X>?">
21+
<Accordion title="How do you compare to `<X>`?">
2222
Ask yourself about `<X>`:
2323

2424
- Is `<X>` open-source?

docs/fern/docs/pages-template/getting-started/setup.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,78 @@ We recommend using our **setup wizard** for a seamless installation experience.
387387

388388
Check out the [Users](./users.mdx) to learn how to retrieve and update user information, or [Example pages](./example-pages.mdx) to see how to build your sign-in/up pages.
389389

390+
391+
{/* ELSE_IF_PLATFORM python */}
392+
393+
<Info>
394+
Welcome to the Python setup guide. If you're looking for guides for other frameworks, check out the [Next.js SDK Setup](../../pages-next/getting-started/setup.mdx), [React SDK Setup](../../pages-react/getting-started/setup.mdx), or the [JavaScript SDK Setup](../../pages-js/getting-started/setup.mdx).
395+
</Info>
396+
397+
Our recommended way to use Stack Auth with Python is with the [REST API](../rest-api/overview.mdx). It provides a fully documented way to interact with Stack Auth from any Python framework, including Flask, FastAPI, and Django.
398+
399+
For the purpose of this guide, we will use the `requests` library to make HTTP requests to the Stack Auth API. If you haven't already, you can install it in your environment with `pip install requests`.
400+
401+
<Steps>
402+
### Create API keys
403+
404+
First, create an account on [the Stack Auth dashboard](https://app.stack-auth.com/projects), and copy your project ID, publishable client key, and secret server key into a safe place (eg. environment variables).
405+
406+
From there, you can access them in your Python code. You can then read them like this:
407+
408+
```python
409+
import os
410+
411+
stack_project_id = os.getenv("STACK_PROJECT_ID")
412+
stack_publishable_client_key = os.getenv("STACK_PUBLISHABLE_CLIENT_KEY")
413+
stack_secret_server_key = os.getenv("STACK_SECRET_SERVER_KEY")
414+
```
415+
416+
### Make a request
417+
418+
Next, create a helper function to make requests to the Stack Auth API:
419+
420+
```python
421+
import requests
422+
423+
def stack_auth_request(method, endpoint, **kwargs):
424+
res = requests.request(
425+
method,
426+
f'https://api.stack-auth.com/{endpoint}',
427+
headers={
428+
'x-stack-access-type': 'server', # or 'client' if you're only accessing the client API
429+
'x-stack-project-id': stack_project_id,
430+
'x-stack-publishable-client-key': stack_publishable_client_key,
431+
'x-stack-secret-server-key': stack_secret_server_key, # not necessary if access type is 'client'
432+
**kwargs.pop('headers', {}),
433+
},
434+
**kwargs,
435+
)
436+
if res.status_code >= 400:
437+
raise Exception(f"Stack Auth API request failed with {res.status_code}: {res.text}")
438+
return res.json()
439+
440+
print(stack_auth_request('GET', '/api/v1/projects/current'))
441+
```
442+
443+
### Retrieve the access tokens
444+
445+
If you're building a backend server, most likely you'll want to use the currently signed in user's access token. Most normally, you would send this with all your requests to the backend in an HTTP header.
446+
447+
In Stack Auth's JavaScript SDK, you can retrieve the access token [from the `stackClientApp` object](/sdk/types/user#currentusergetauthjson). Then, you can use said access token to make requests to Stack Auth:
448+
449+
```python
450+
access_token = # access token retrieved from the JavaScript SDK
451+
452+
print(stack_auth_request('GET', '/api/v1/users/me', headers={
453+
'x-stack-access-token': access_token,
454+
}))
455+
```
456+
457+
### Done!
458+
</Steps>
459+
460+
## Next steps
461+
462+
Check out the [REST API documentation](../rest-api/overview.mdx) to learn more about the available endpoints and how to use them in your Python application.
463+
390464
{/* END_PLATFORM */}

docs/fern/docs/pages-template/overview.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ You can get started in five minutes with our [setup guide](./getting-started/set
2222
Use our pre-built React components, or create your own
2323
</Card>
2424
{/* END_PLATFORM */}
25+
{/* IF_PLATFORM: js-like */}
2526
<Card
2627
title="SDK Reference"
2728
icon="fa-regular fa-file-lines"
2829
href="/sdk"
2930
>
30-
Learn how to use Stack's SDK
31+
Learn how to use Stack Auth's SDK
3132
</Card>
33+
{/* END_PLATFORM */}
3234
<Card
3335
title="REST API Reference"
3436
icon="fa-solid fa-code"
@@ -40,17 +42,17 @@ You can get started in five minutes with our [setup guide](./getting-started/set
4042

4143
Still have questions? Check out our [FAQ](/faq) or [join our Discord](https://discord.stack-auth.com).
4244

43-
## Why Choose Stack?
45+
## Why Choose Stack Auth?
4446

4547
Authentication is inherently difficult. Few things are more sensitive than user data and more complex than cryptography. Not surprisingly, many online businesses struggle to get it right.
4648

4749
The optimal authentication solution should be secure, yet approachable. If developers need to worry about JWTs, OAuth flows, or password hashing, then the authentication solution has failed its purpose. If an authentication solution uses closed-source, unauditable code for the most critical parts of your application, then we have failed.
4850

4951
In truth, the authentication services industry has collectively failed. It's dominated by proprietary giants with predatory "bait-and-switch" pricing, providing no transparency into their codebase and delivering a subpar developer experience — because they know enterprises will pay more if setting up auth systems is painful.
5052

51-
That's why we built Stack. Integrating secure authentication into your app should take **5 minutes**, not 5 days.
53+
That's why we built Stack Auth. Integrating secure authentication into your app should take **5 minutes**, not 5 days.
5254

53-
At the core of Stack are deep integrations into frontend and backend frameworks. We offer the best developer experience with Next.js. Instead of providing mediocre support for numerous frameworks, we focused on making a few integrations excellent before adding new ones. We also offer a cross-compatible REST API as a fallback.
55+
At the core of Stack Auth are deep integrations into frontend and backend frameworks. We offer the best developer experience with Next.js. Instead of providing mediocre support for numerous frameworks, we focused on making a few integrations excellent before adding new ones. We also offer a cross-compatible REST API as a fallback.
5456

5557
Here's an example. To get the current user, simply call:
5658

@@ -61,7 +63,7 @@ export function MyComponent() {
6163
}
6264
```
6365

64-
That's it! Stack will either return a User object or redirect the user to the login page.
66+
That's it! Stack Auth will either return a User object or redirect the user to the login page.
6567

6668
You can also add a button to change the user's name:
6769

@@ -100,9 +102,9 @@ To manage everything efficiently, there is a powerful admin dashboard:
100102

101103
![Stack dashboard](./imgs/dashboard.png)
102104

103-
Best of all, Stack is **100% open-source**. This means the client, server, dashboard, and even this documentation you're reading right now. Check out our [GitHub](https://github.com/stack-auth/stack-auth) to open an issue or pull request.
105+
Best of all, Stack Auth is **100% open-source**. This means the client, server, dashboard, and even this documentation you're reading right now. Check out our [GitHub](https://github.com/stack-auth/stack-auth) to open an issue or pull request.
104106

105-
This is just a glimpse of what Stack can do. Stack also handles many other tasks like backend integration, data storage, emails, teams, permissions, and more, which you will learn about later in the documentation.
107+
This is just a glimpse of what Stack Auth can do. We also handle many other tasks like backend integration, data storage, emails, teams, permissions, and more, which you will learn about later in the documentation.
106108

107109
If this sounds interesting, [get started](/getting-started/setup) with our interactive setup wizard, or join [our Discord community](https://discord.stack-auth.com) to ask questions and get help from our team.
108110

docs/fern/docs/pages-template/sdk/types/user.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ requests. Similar to `getAuthJson`, but specifically for HTTP requests.
10581058

10591059
If you are using `tokenStore: "cookie"`, you don't need this for same-origin requests. However, most
10601060
browsers now disable third-party cookies by default, so we must pass authentication tokens by header instead
1061-
if the client and server are on different hostnames.
1061+
if the client and server are on different origins.
10621062

10631063
This function returns a header object that can be used with `fetch` or other HTTP request libraries to send
10641064
authenticated requests.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"repository": "",
66
"scripts": {
77
"pre-no-codegen": "npx -y only-allow pnpm",
8-
"pre-preinstall": "npx -y only-allow pnpm && node -e \"if(process.env.STACK_SKIP_TEMPLATE_GENERATION !== 'true') require('child_process').execSync('npx --package=tsx tsx ./scripts/generate-sdks.ts')\"",
9-
"pre": "pnpm pre-preinstall && node -e \"if(process.env.STACK_SKIP_TEMPLATE_GENERATION !== 'true') { require('child_process').execSync('pnpm run generate-docs') }\"",
8+
"pre-preinstall": "npx -y only-allow pnpm && node -e \"if(process.env.STACK_SKIP_TEMPLATE_GENERATION !== 'true') require('child_process').execSync('npx --package=tsx tsx ./scripts/generate-sdks.ts', {stdio: 'inherit'})\"",
9+
"pre": "pnpm pre-preinstall && node -e \"if(process.env.STACK_SKIP_TEMPLATE_GENERATION !== 'true') { require('child_process').execSync('pnpm run generate-docs', {stdio: 'inherit'}) }\"",
1010
"preinstall": "pnpm pre-preinstall",
1111
"typecheck": "pnpm pre && turbo typecheck",
1212
"build:dev": "pnpm pre && NODE_ENV=development pnpm run build",

packages/template/src/lib/stack-app/users/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type Auth = {
3232
*
3333
* If you are using `tokenStore: "cookie"`, you don't need this for same-origin requests. However, most
3434
* browsers now disable third-party cookies by default, so we must pass authentication tokens by header instead
35-
* if the client and server are on different hostnames.
35+
* if the client and server are on different origins.
3636
*
3737
* This function returns a header object that can be used with `fetch` or other HTTP request libraries to send
3838
* authenticated requests.

0 commit comments

Comments
 (0)