Skip to content

Commit c37d3ae

Browse files
authored
(chore): update readme
1 parent e86b7d5 commit c37d3ae

File tree

1 file changed

+112
-31
lines changed

1 file changed

+112
-31
lines changed

README.md

Lines changed: 112 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,136 @@
1-
<!-- Begin Title, generated by Fern -->
2-
# Fileforge Python Library
1+
# FileForge Python Library
32

43
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)
54

6-
The Fileforge Python Library provides convenient access to the Fileforge API from applications written in Python.
7-
<!-- End Title -->
5+
The FileForge Python Library provides convenient access to the FileForge API from
6+
applications written in Python.
87

9-
<!-- Begin Installation, generated by Fern -->
10-
# Installation
8+
The library includes type definitions for all
9+
request and response fields, and offers both synchronous and asynchronous clients powered by httpx.
1110

12-
```sh
13-
pip install --upgrade fileforge
11+
## Installation
12+
13+
Add this dependency to your project's build file:
14+
15+
```bash
16+
pip install fileforge
17+
# or
18+
poetry add fileforge
19+
```
20+
21+
## Usage
22+
Simply import `FileForge` and start making calls to our API.
23+
24+
```python
25+
from fileforge import GenerateRequestOptions
26+
from fileforge.client import FileForge
27+
28+
client = FileForge(
29+
api_key="YOUR_API_KEY" # Defaults to FILEFORGE_API_KEY
30+
)
31+
client.generate(
32+
options=GenerateRequestOptions(),
33+
files=["path/to/file1", "path/to/file2"]
34+
)
35+
```
36+
37+
## Async Client
38+
The SDK also exports an async client so that you can make non-blocking
39+
calls to our API.
40+
41+
```python
42+
from fileforge import GenerateRequestOptions
43+
from fileforge.client import AsyncFileForge
44+
45+
client = AsyncFileForge(
46+
api_key="YOUR_API_KEY" # Defaults to FILEFORGE_API_KEY
47+
)
48+
49+
async def main() -> None:
50+
client.generate(
51+
options=GenerateRequestOptions(),
52+
files=["path/to/file1", "path/to/file2"]
53+
)
54+
asyncio.run(main())
1455
```
15-
<!-- End Installation -->
1656

17-
<!-- Begin Usage, generated by Fern -->
18-
# Usage
57+
## Exception Handling
58+
All errors thrown by the SDK will be subclasses of [`ApiError`](./src/schematic/core/api_error.py).
1959

2060
```python
21-
from fileforge.client import Fileforge
61+
import fileforge
2262

23-
client = Fileforge(
24-
api_key="YOUR_API_KEY",
63+
try:
64+
client.generate(...)
65+
except fileforge.core.ApiError as e: # Handle all errors
66+
print(e.status_code)
67+
print(e.body)
68+
```
69+
70+
## Advanced
71+
72+
### Timeouts
73+
By default, requests time out after 60 seconds. You can configure this with a
74+
timeout option at the client or request level.
75+
76+
```python
77+
from fileforge.client import FileForge
78+
79+
client = FileForge(
80+
# All timeouts are 20 seconds
81+
timeout=20.0,
2582
)
83+
84+
# Override timeout for a specific method
85+
fileforge.generate(..., {
86+
timeout_in_seconds=20.0
87+
})
88+
```
89+
90+
### Retries
91+
The SDK is instrumented with automatic retries with exponential backoff. A request will be
92+
retried as long as the request is deemed retriable and the number of retry attempts has not grown larger
93+
than the configured retry limit (default: 2).
94+
95+
A request is deemed retriable when any of the following HTTP status codes is returned:
96+
97+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
98+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
99+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
100+
101+
Use the `max_retries` request option to configure this behavior.
102+
103+
```python
104+
client.generate(..., {
105+
max_retries=1
106+
})
26107
```
27-
<!-- End Usage -->
28108

29-
<!-- Begin Async Usage, generated by Fern -->
30-
# Async Client
109+
### Custom HTTP client
110+
You can override the httpx client to customize it for your use-case. Some common use-cases
111+
include support for proxies and transports.
31112

32113
```python
33-
from fileforge.client import AsyncFileforge
114+
import httpx
115+
116+
from fileforge.client import FileForge
34117

35-
client = AsyncFileforge(
36-
api_key="YOUR_API_KEY",
118+
client = FileForge(
119+
http_client=httpx.Client(
120+
proxies="http://my.test.proxy.example.com",
121+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
122+
),
37123
)
38124
```
39-
<!-- End Async Usage -->
40125

41-
<!-- Begin Status, generated by Fern -->
42-
# Beta Status
126+
## Beta Status
43127

44-
This SDK is in beta, and there may be breaking changes between versions without a major
45-
version update. Therefore, we recommend pinning the package version to a specific version.
46-
This way, you can install the same version each time without breaking changes.
47-
<!-- End Status -->
128+
This SDK is in **Preview**, and there may be breaking changes between versions without a major
129+
version update.
48130

49-
<!-- Begin Contributing, generated by Fern -->
50-
# Contributing
131+
To ensure a reproducible environment (and minimize risk of breaking changes), we recommend pinning a specific package version.
132+
133+
## Contributing
51134

52135
While we value open-source contributions to this SDK, this library is generated programmatically.
53136
Additions made directly to this library would have to be moved over to our generation code,
@@ -56,5 +139,3 @@ otherwise they would be overwritten upon the next generated release. Feel free t
56139
an issue first to discuss with us!
57140

58141
On the other hand, contributions to the README are always very welcome!
59-
<!-- End Contributing -->
60-

0 commit comments

Comments
 (0)