Skip to content

Commit aa5012d

Browse files
committed
docs: add Python SDK, update to v1.0.0
- Quick start now covers both Express.js and FastAPI/Starlette - Configuration page documents all options for both SDKs with code tabs - Dashboard page notes the UI is shared across SDKs - Insights and Release Tracking pages add Python examples - Homepage features mention both Node.js and Python SDKs - Nav version bump 0.1.0 → 1.0.0, add PyPI link and Python changelog
1 parent 14647ea commit aa5012d

7 files changed

Lines changed: 193 additions & 86 deletions

File tree

docs/.vitepress/config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export default defineConfig({
2121
{ text: 'Features', link: '/features/insights' },
2222
{ text: 'API Reference', link: '/guide/configuration' },
2323
{
24-
text: 'v0.1.0',
24+
text: 'v1.0.0',
2525
items: [
26-
{ text: 'Changelog', link: 'https://github.com/APIForge-Organisation/sdk-nodejs/blob/main/CHANGELOG.md' },
27-
{ text: 'npm', link: 'https://www.npmjs.com/package/apiforgejs' },
26+
{ text: 'Changelog (Node.js)', link: 'https://github.com/APIForge-Organisation/sdk-nodejs/blob/main/CHANGELOG.md' },
27+
{ text: 'Changelog (Python)', link: 'https://github.com/APIForge-Organisation/sdk-python/blob/main/CHANGELOG.md' },
28+
{ text: 'npm — apiforgejs', link: 'https://www.npmjs.com/package/apiforgejs' },
29+
{ text: 'PyPI — apiforgepy', link: 'https://pypi.org/project/apiforgepy/' },
2830
],
2931
},
3032
],
@@ -61,6 +63,7 @@ export default defineConfig({
6163
socialLinks: [
6264
{ icon: 'github', link: 'https://github.com/APIForge-Organisation' },
6365
{ icon: 'npm', link: 'https://www.npmjs.com/package/apiforgejs' },
66+
{ icon: { svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>PyPI</title><path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm-.535 2.636c2.11 0 3.532.478 4.181 1.072.649.593.787 1.377.787 2.206v4.073c0 .843-.638 1.56-1.48 1.56H9.027c-1.156 0-2.086.945-2.086 2.1v1.574H4.87c-.86 0-1.322-.614-1.322-1.574V7.18c0-2.473 2.107-4.544 7.917-4.544zm-.34 1.406c-.607 0-1.099.493-1.099 1.1s.492 1.099 1.099 1.099c.607 0 1.099-.492 1.099-1.1 0-.606-.492-1.099-1.1-1.099zm4.772 8.205v1.574c0 .96-.463 1.574-1.322 1.574h-2.07v1.574c0 1.156-.93 2.1-2.087 2.1H5.502c-.842 0-1.48-.717-1.48-1.56v-4.073c0-.829.138-1.613.787-2.206.649-.594 2.07-1.072 4.18-1.072 5.811 0 7.918 2.07 7.918 4.544v-.455zm-3.83 4.648c-.607 0-1.1.492-1.1 1.099s.493 1.099 1.1 1.099c.606 0 1.098-.492 1.098-1.1 0-.606-.492-1.098-1.099-1.098z"/></svg>' }, link: 'https://pypi.org/project/apiforgepy/' },
6467
],
6568

6669
editLink: {

docs/features/insights.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Identifies endpoints that have received no traffic for an extended period — sa
2222

2323
> *"`DELETE /legacy/import` has received no requests in 23 days. Consider deprecating this endpoint."*
2424
25-
**Triggers when:** An endpoint has zero requests for the past **21 days** (configurable via `deadThresholdDays`).
25+
**Triggers when:** An endpoint has zero requests for the past **21 days**.
2626

2727
---
2828

@@ -53,11 +53,24 @@ Insights are sorted by severity in the dashboard:
5353

5454
Set the `release` option to activate `PERF` and `OK` insights:
5555

56-
```js
56+
::: code-group
57+
58+
```js [Node.js]
5759
app.use(apiforge({
5860
mode: 'local',
59-
release: process.env.npm_package_version, // e.g. '1.4.0'
61+
release: process.env.npm_package_version,
6062
}))
6163
```
6264

65+
```python [Python]
66+
import os
67+
app.add_middleware(
68+
ApiForgeMiddleware,
69+
mode="local",
70+
release=os.environ.get("RELEASE"),
71+
)
72+
```
73+
74+
:::
75+
6376
Each time the value changes (i.e. on a new deploy), APIForge creates a comparison baseline automatically.

docs/features/release-tracking.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,40 @@ Release tracking automatically compares your API's performance before and after
66

77
Pass the current version as the `release` option:
88

9-
```js
9+
::: code-group
10+
11+
```js [Node.js]
1012
app.use(apiforge({
1113
mode: 'local',
1214
release: process.env.npm_package_version,
1315
}))
1416
```
1517

18+
```python [Python]
19+
import os
20+
app.add_middleware(
21+
ApiForgeMiddleware,
22+
mode="local",
23+
release=os.environ.get("RELEASE"),
24+
)
25+
```
26+
27+
:::
28+
1629
Or hardcode it during the deploy process:
1730

18-
```js
19-
app.use(apiforge({
20-
mode: 'local',
21-
release: 'v1.4.0',
22-
}))
31+
::: code-group
32+
33+
```js [Node.js]
34+
app.use(apiforge({ mode: 'local', release: 'v1.4.0' }))
35+
```
36+
37+
```python [Python]
38+
app.add_middleware(ApiForgeMiddleware, mode="local", release="v1.4.0")
2339
```
2440

41+
:::
42+
2543
::: tip Automate with environment variables
2644
Most CI/CD systems expose the version or git tag as an environment variable. Inject it at build time so it changes automatically on every deploy.
2745
:::

docs/guide/configuration.md

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Configuration
22

3+
## Node.js
4+
35
All options are passed to the `apiforge()` factory. Every option is optional except `mode`.
46

57
```js
@@ -16,82 +18,113 @@ app.use(apiforge({
1618
}))
1719
```
1820

21+
## Python
22+
23+
All options are passed to `ApiForgeMiddleware`. Every option is optional except `mode`.
24+
25+
```python
26+
app.add_middleware(
27+
ApiForgeMiddleware,
28+
mode="local",
29+
db_path=".apiforge.db",
30+
dashboard_port=4242,
31+
flush_interval=60,
32+
env="production",
33+
release="v1.4.0",
34+
service="user-service",
35+
sampling=1.0,
36+
ignore_paths=["/favicon.ico", "/health"],
37+
)
38+
```
39+
40+
::: tip Python naming
41+
Python uses `snake_case` for option names. `flush_interval` is in **seconds** (not milliseconds).
42+
:::
43+
44+
---
45+
1946
## Options
2047

21-
### `mode`
48+
### `mode` / `mode`
2249

2350
- **Type:** `'local'`
2451
- **Required:** yes
25-
- **Default:**
2652

27-
The storage and transport mode. Only `'local'` (SQLite) is available in v0.x. SaaS mode is planned for v1.0.
53+
The storage and transport mode. Only `'local'` (SQLite) is available. SaaS mode is planned for a future version.
2854

2955
---
3056

31-
### `dbPath`
57+
### `dbPath` / `db_path`
3258

3359
- **Type:** `string`
3460
- **Default:** `'.apiforge.db'`
3561

36-
Path to the SQLite database file. The file is created automatically if it does not exist.
37-
38-
```js
39-
apiforge({ mode: 'local', dbPath: '/var/data/apiforge.db' })
40-
```
62+
Path to the SQLite database file. Created automatically if it does not exist.
4163

4264
---
4365

44-
### `dashboardPort`
66+
### `dashboardPort` / `dashboard_port`
4567

46-
- **Type:** `number`
68+
- **Type:** `number` / `int`
4769
- **Default:** `4242`
4870

4971
Port for the local dashboard HTTP server. Set to `0` to disable the dashboard entirely.
5072

5173
```js
52-
apiforge({ mode: 'local', dashboardPort: 0 }) // no dashboard
53-
apiforge({ mode: 'local', dashboardPort: 9000 }) // custom port
74+
// Node.js
75+
apiforge({ mode: 'local', dashboardPort: 0 }) // no dashboard
76+
apiforge({ mode: 'local', dashboardPort: 9000 }) // custom port
77+
```
78+
79+
```python
80+
# Python
81+
ApiForgeMiddleware(mode="local", dashboard_port=0) # no dashboard
82+
ApiForgeMiddleware(mode="local", dashboard_port=9000) # custom port
5483
```
5584

5685
---
5786

58-
### `flushInterval`
87+
### `flushInterval` / `flush_interval`
5988

60-
- **Type:** `number` (milliseconds)
61-
- **Default:** `60000` (60 seconds)
89+
- **Type (Node.js):** `number` (milliseconds) — Default: `60000`
90+
- **Type (Python):** `int` (seconds) — Default: `60`
6291

63-
How often the in-memory buffer is flushed to SQLite. Lower values give more granular data at the cost of more frequent writes.
92+
How often the in-memory buffer is flushed to SQLite.
6493

6594
::: warning Minimum recommended value
66-
Values below `5000` (5s) may impact performance under high traffic. The default of 60s is appropriate for most applications.
95+
Values below 5 seconds may impact performance under high traffic. The default of 60s is appropriate for most applications.
6796
:::
6897

6998
---
7099

71100
### `env`
72101

73102
- **Type:** `string`
74-
- **Default:** `process.env.NODE_ENV ?? 'production'`
103+
- **Default (Node.js):** `process.env.NODE_ENV ?? 'production'`
104+
- **Default (Python):** `'production'`
75105

76-
Environment label stored with each metric. Useful when running multiple environments pointing to the same database.
77-
78-
```js
79-
apiforge({ mode: 'local', env: process.env.NODE_ENV })
80-
```
106+
Environment label stored with each metric.
81107

82108
---
83109

84110
### `release`
85111

86112
- **Type:** `string | null`
87-
- **Default:** `process.env.APP_VERSION ?? null`
113+
- **Default:** `null`
88114

89115
Version tag for the current deployment. When provided, APIForge creates a comparison point in the timeline and generates before/after insights after each deploy.
90116

91117
```js
118+
// Node.js
92119
apiforge({ mode: 'local', release: process.env.npm_package_version })
93120
```
94121

122+
```python
123+
# Python
124+
import os
125+
ApiForgeMiddleware(mode="local", release=os.environ.get("RELEASE"))
126+
```
127+
95128
See [Release Tracking](/features/release-tracking) for details.
96129

97130
---
@@ -103,42 +136,29 @@ See [Release Tracking](/features/release-tracking) for details.
103136

104137
Service name, used to distinguish multiple APIs sharing the same database.
105138

106-
```js
107-
apiforge({ mode: 'local', service: 'payment-api' })
108-
```
109-
110139
---
111140

112141
### `sampling`
113142

114-
- **Type:** `number` (0.0 – 1.0)
143+
- **Type:** `number / float` (0.0 – 1.0)
115144
- **Default:** `1.0`
116145

117146
Fraction of requests to instrument. Set below `1.0` under very high traffic to reduce overhead.
118147

119-
```js
120-
apiforge({ mode: 'local', sampling: 0.1 }) // instrument 10% of requests
121-
```
122-
123148
---
124149

125-
### `ignorePaths`
150+
### `ignorePaths` / `ignore_paths`
126151

127-
- **Type:** `string[]`
152+
- **Type:** `string[]` / `list[str]`
128153
- **Default:** `['/favicon.ico']`
129154

130155
Paths to exclude from instrumentation. Supports exact matches.
131156

132-
```js
133-
apiforge({
134-
mode: 'local',
135-
ignorePaths: ['/favicon.ico', '/health', '/ready', '/metrics'],
136-
})
137-
```
157+
---
138158

139159
## Graceful shutdown
140160

141-
The middleware exposes a `shutdown()` method for clean teardown (flushes the buffer and closes the SQLite connection):
161+
### Node.js
142162

143163
```js
144164
const mw = apiforge({ mode: 'local' })
@@ -149,3 +169,14 @@ process.on('SIGTERM', () => {
149169
server.close()
150170
})
151171
```
172+
173+
### Python
174+
175+
```python
176+
import atexit
177+
178+
mw = ApiForgeMiddleware(mode="local")
179+
app.add_middleware(mw)
180+
181+
atexit.register(mw.shutdown)
182+
```

docs/guide/dashboard.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Local Dashboard
22

3-
The local dashboard is a built-in web UI served automatically by the SDK on port 4242 (configurable).
3+
The local dashboard is a built-in web UI served automatically by the SDK on port 4242 (configurable). It is identical across all SDKs — the same interface whether you run Node.js or Python.
44

55
```
66
http://localhost:4242
@@ -35,7 +35,7 @@ All instrumented routes, sorted by request volume. Columns:
3535

3636
| Column | Description |
3737
|---|---|
38-
| Route | Parameterized pattern — e.g. `GET /users/:id` |
38+
| Route | Parameterized pattern — e.g. `GET /users/:id` or `GET /users/{user_id}` |
3939
| Requests | Total calls in the selected time range |
4040
| P50 / P90 / P99 | Latency percentiles in milliseconds |
4141
| Error rate | Percentage of 4xx + 5xx responses |
@@ -47,21 +47,34 @@ Automatically generated alerts — no configuration required. See [Automatic Ins
4747

4848
## Disabling the dashboard
4949

50-
Set `dashboardPort: 0` in your config:
50+
::: code-group
5151

52-
```js
52+
```js [Node.js]
5353
app.use(apiforge({ mode: 'local', dashboardPort: 0 }))
5454
```
5555

56-
This is useful in production environments where you don't want to expose an extra port, or in test environments.
56+
```python [Python]
57+
app.add_middleware(ApiForgeMiddleware, mode="local", dashboard_port=0)
58+
```
59+
60+
:::
5761

5862
## Custom port
5963

60-
```js
64+
::: code-group
65+
66+
```js [Node.js]
6167
app.use(apiforge({ mode: 'local', dashboardPort: 9090 }))
6268
// Dashboard → http://localhost:9090
6369
```
6470

71+
```python [Python]
72+
app.add_middleware(ApiForgeMiddleware, mode="local", dashboard_port=9090)
73+
# Dashboard → http://localhost:9090
74+
```
75+
76+
:::
77+
6578
## Security note
6679

6780
The dashboard has no authentication in local mode. **Do not expose port 4242 to the public internet.** Use a firewall rule or SSH tunnel if you need to access it remotely:

0 commit comments

Comments
 (0)