feat: add Node.js and Python SDKs
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m1s

- Node.js SDK: TypeScript, ESM+CJS, zero deps (uses native fetch)
- Python SDK: zero deps (uses urllib), Python 3.8+
- Both fully documented with examples and type hints
- Ready for npm/PyPI publishing
This commit is contained in:
OpenClawd 2026-02-23 14:02:15 +00:00
parent db1fa8d506
commit 66ecc471cf
8 changed files with 709 additions and 0 deletions

126
sdk/node/README.md Normal file
View file

@ -0,0 +1,126 @@
# SnapAPI Node.js SDK
Official Node.js client for [SnapAPI](https://snapapi.eu) — the EU-hosted screenshot API.
## Installation
```bash
npm install snapapi
```
## Quick Start
```typescript
import { SnapAPI } from 'snapapi';
import fs from 'fs';
const snap = new SnapAPI('your-api-key');
// Simple screenshot
const png = await snap.capture('https://example.com');
fs.writeFileSync('screenshot.png', png);
```
## Usage
### Basic Screenshot
```typescript
const screenshot = await snap.capture('https://example.com');
```
### With Options
```typescript
const screenshot = await snap.capture('https://example.com', {
format: 'jpeg',
width: 1920,
height: 1080,
quality: 90,
});
```
### Full-Page Capture
```typescript
const screenshot = await snap.capture({
url: 'https://example.com/blog',
fullPage: true,
format: 'png',
deviceScale: 2, // Retina
});
```
### Mobile Viewport
```typescript
const screenshot = await snap.capture({
url: 'https://example.com',
width: 375,
height: 812,
deviceScale: 2,
});
```
### Wait for Dynamic Content
```typescript
const screenshot = await snap.capture({
url: 'https://example.com/dashboard',
waitForSelector: '#chart-loaded',
waitUntil: 'networkidle2',
});
```
## API Reference
### `new SnapAPI(apiKey, config?)`
| Parameter | Type | Description |
|-----------|------|-------------|
| `apiKey` | `string` | Your SnapAPI API key (required) |
| `config.baseUrl` | `string` | API base URL (default: `https://snapapi.eu`) |
| `config.timeout` | `number` | Request timeout in ms (default: `30000`) |
### `snap.capture(url, options?)` / `snap.capture(options)`
Returns a `Promise<Buffer>` containing the screenshot image.
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `url` | `string` | — | URL to capture (required) |
| `format` | `'png' \| 'jpeg' \| 'webp'` | `'png'` | Output format |
| `width` | `number` | `1280` | Viewport width (3203840) |
| `height` | `number` | `800` | Viewport height (2002160) |
| `fullPage` | `boolean` | `false` | Capture full scrollable page |
| `quality` | `number` | `80` | JPEG/WebP quality (1100) |
| `waitForSelector` | `string` | — | CSS selector to wait for |
| `deviceScale` | `number` | `1` | Device pixel ratio (13) |
| `delay` | `number` | `0` | Extra delay in ms (05000) |
| `waitUntil` | `string` | `'domcontentloaded'` | Load event to wait for |
### `snap.health()`
Returns API health status.
### Error Handling
```typescript
import { SnapAPI, SnapAPIError } from 'snapapi';
try {
const screenshot = await snap.capture('https://example.com');
} catch (err) {
if (err instanceof SnapAPIError) {
console.error(`API error ${err.status}: ${err.detail}`);
}
}
```
## EU-Hosted & GDPR Compliant
SnapAPI runs entirely on EU infrastructure (Germany). Your data never leaves the EU. [Learn more](https://snapapi.eu).
## License
MIT — [Cloonar Technologies GmbH](https://snapapi.eu)