parze 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -10
- package/dist/index.d.ts +10 -2
- package/dist/index.js +61 -9
- package/package.json +5 -11
package/README.md
CHANGED
|
@@ -1,29 +1,84 @@
|
|
|
1
1
|
# Parze JavaScript SDK
|
|
2
2
|
|
|
3
|
-
TypeScript/JavaScript client for the Parze API.
|
|
3
|
+
Official TypeScript/JavaScript client for the Parze document parsing API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install parze
|
|
8
|
+
npm install parze
|
|
9
9
|
# or
|
|
10
|
-
yarn add parze
|
|
10
|
+
yarn add parze
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Quick Start
|
|
14
14
|
|
|
15
|
-
```
|
|
16
|
-
import { ParzeClient } from
|
|
15
|
+
```typescript
|
|
16
|
+
import { ParzeClient } from 'parze';
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// Initialize client with your API key
|
|
19
|
+
const client = new ParzeClient({ apiKey: 'pk_live_your_key_here' });
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
// Parse a document
|
|
22
|
+
const result = await client.parse('invoice.pdf');
|
|
23
|
+
console.log(result.text);
|
|
24
|
+
|
|
25
|
+
// Extract structured data
|
|
26
|
+
const extraction = await client.extract(result.text, {
|
|
27
|
+
invoice_number: { type: 'string', description: 'Invoice number' },
|
|
28
|
+
total_amount: { type: 'string', description: 'Total amount' },
|
|
29
|
+
date: { type: 'string', description: 'Invoice date' }
|
|
22
30
|
});
|
|
31
|
+
console.log(extraction.extraction);
|
|
23
32
|
|
|
24
|
-
|
|
33
|
+
// Get AI-suggested schema
|
|
34
|
+
const suggested = await client.suggestSchema(result.text);
|
|
35
|
+
console.log(suggested);
|
|
25
36
|
```
|
|
26
37
|
|
|
38
|
+
## API Reference
|
|
39
|
+
|
|
40
|
+
### `parse(filePath, options?)`
|
|
41
|
+
Parse a document into structured text.
|
|
42
|
+
|
|
43
|
+
**Parameters:**
|
|
44
|
+
- `filePath` (string): Path to document file
|
|
45
|
+
- `options` (object, optional):
|
|
46
|
+
- `outputFormat`: "structured" | "markdown" | "json"
|
|
47
|
+
- `preserveTables`: boolean
|
|
48
|
+
- `preserveLayout`: boolean
|
|
49
|
+
- `extractionMode`: "auto" | "ocr_only" | "llm_only" | "identity_doc"
|
|
50
|
+
|
|
51
|
+
**Returns:** Promise with parsed text and metadata
|
|
52
|
+
|
|
53
|
+
### `extract(text, extractionSchema)`
|
|
54
|
+
Extract structured data from text using a schema.
|
|
55
|
+
|
|
56
|
+
**Parameters:**
|
|
57
|
+
- `text` (string): Document text (from parse)
|
|
58
|
+
- `extractionSchema` (object): Schema defining fields to extract
|
|
59
|
+
|
|
60
|
+
**Returns:** Promise with extracted data and confidence scores
|
|
61
|
+
|
|
62
|
+
### `suggestSchema(text)`
|
|
63
|
+
Get AI-suggested extraction schema based on document text.
|
|
64
|
+
|
|
65
|
+
**Parameters:**
|
|
66
|
+
- `text` (string): Document text
|
|
67
|
+
|
|
68
|
+
**Returns:** Promise with suggested schema
|
|
69
|
+
|
|
70
|
+
### `textToSchema(description)`
|
|
71
|
+
Convert natural language description to extraction schema.
|
|
72
|
+
|
|
73
|
+
**Parameters:**
|
|
74
|
+
- `description` (string): Natural language description of fields
|
|
75
|
+
|
|
76
|
+
**Returns:** Promise with generated schema
|
|
77
|
+
|
|
78
|
+
## Get API Key
|
|
79
|
+
|
|
80
|
+
Get your API key from [platform.parze.ai](https://platform.parze.ai)
|
|
81
|
+
|
|
27
82
|
## Development
|
|
28
83
|
|
|
29
84
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,19 @@ export interface ParzeClientOptions {
|
|
|
2
2
|
apiKey: string;
|
|
3
3
|
baseUrl?: string;
|
|
4
4
|
}
|
|
5
|
+
export interface ParseOptions {
|
|
6
|
+
outputFormat?: 'structured' | 'markdown' | 'json';
|
|
7
|
+
preserveTables?: boolean;
|
|
8
|
+
preserveLayout?: boolean;
|
|
9
|
+
extractionMode?: 'auto' | 'ocr_only' | 'llm_only' | 'identity_doc';
|
|
10
|
+
}
|
|
5
11
|
export declare class ParzeClient {
|
|
6
12
|
private apiKey;
|
|
7
13
|
private baseUrl;
|
|
8
14
|
private http;
|
|
9
15
|
constructor(options: ParzeClientOptions);
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
parse(filePath: string, options?: ParseOptions): Promise<any>;
|
|
17
|
+
extract(text: string, extractionSchema: object): Promise<any>;
|
|
18
|
+
suggestSchema(text: string): Promise<any>;
|
|
19
|
+
textToSchema(description: string): Promise<any>;
|
|
12
20
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,34 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.ParzeClient = void 0;
|
|
7
40
|
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
8
43
|
class ParzeClient {
|
|
9
44
|
constructor(options) {
|
|
10
45
|
this.apiKey = options.apiKey;
|
|
11
|
-
this.baseUrl = options.baseUrl || 'https://
|
|
46
|
+
this.baseUrl = options.baseUrl || 'https://parze-561514618654.europe-west1.run.app';
|
|
12
47
|
this.http = axios_1.default.create({
|
|
13
48
|
baseURL: this.baseUrl + '/api',
|
|
14
49
|
headers: {
|
|
15
50
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
51
|
},
|
|
18
52
|
});
|
|
19
53
|
}
|
|
20
|
-
async
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
54
|
+
async parse(filePath, options) {
|
|
55
|
+
const form = new form_data_1.default();
|
|
56
|
+
form.append('file', fs.createReadStream(filePath));
|
|
57
|
+
if (options === null || options === void 0 ? void 0 : options.outputFormat)
|
|
58
|
+
form.append('output_format', options.outputFormat);
|
|
59
|
+
if ((options === null || options === void 0 ? void 0 : options.preserveTables) !== undefined)
|
|
60
|
+
form.append('preserve_tables', String(options.preserveTables));
|
|
61
|
+
if ((options === null || options === void 0 ? void 0 : options.preserveLayout) !== undefined)
|
|
62
|
+
form.append('preserve_layout', String(options.preserveLayout));
|
|
63
|
+
if (options === null || options === void 0 ? void 0 : options.extractionMode)
|
|
64
|
+
form.append('extraction_mode', options.extractionMode);
|
|
65
|
+
const response = await this.http.post('/parse', form, {
|
|
66
|
+
headers: form.getHeaders(),
|
|
24
67
|
});
|
|
25
68
|
return response.data;
|
|
26
69
|
}
|
|
27
|
-
async
|
|
28
|
-
const response = await this.http.post('/
|
|
29
|
-
|
|
70
|
+
async extract(text, extractionSchema) {
|
|
71
|
+
const response = await this.http.post('/extract', {
|
|
72
|
+
text,
|
|
73
|
+
extraction_schema: extractionSchema,
|
|
30
74
|
});
|
|
31
75
|
return response.data;
|
|
32
76
|
}
|
|
77
|
+
async suggestSchema(text) {
|
|
78
|
+
const response = await this.http.post('/suggest-schema', { text });
|
|
79
|
+
return response.data;
|
|
80
|
+
}
|
|
81
|
+
async textToSchema(description) {
|
|
82
|
+
const response = await this.http.post('/text-to-schema', { text: description });
|
|
83
|
+
return response.data;
|
|
84
|
+
}
|
|
33
85
|
}
|
|
34
86
|
exports.ParzeClient = ParzeClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parze",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for the Parze API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,15 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"author": "gideononyewuenyi",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "https://github.com/parze/parze.git",
|
|
21
|
-
"directory": "sdk/js"
|
|
22
|
-
},
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/parze/parze/issues"
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://parze.com",
|
|
18
|
+
"homepage": "https://platform.parze.ai",
|
|
27
19
|
"keywords": [
|
|
28
20
|
"parze",
|
|
29
21
|
"sdk",
|
|
@@ -31,9 +23,11 @@
|
|
|
31
23
|
"api-client"
|
|
32
24
|
],
|
|
33
25
|
"dependencies": {
|
|
34
|
-
"axios": "^1.6.0"
|
|
26
|
+
"axios": "^1.6.0",
|
|
27
|
+
"form-data": "^4.0.0"
|
|
35
28
|
},
|
|
36
29
|
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.0.0",
|
|
37
31
|
"typescript": "^5.0.0"
|
|
38
32
|
}
|
|
39
33
|
}
|