Python SDK for Writer API
Project description
SDK Installation
pip install writerai
Authentication
Writer authenticates your API requests using your account’s API keys. If you do not include your key when making an API request, or use one that is incorrect or outdated, Writer returns an error.
Your API keys are available in the account dashboard. We include randomly generated API keys in our code examples if you are not logged in. Replace these with your own or log in to see code examples populated with your own API keys.
If you cannot see your secret API keys in the Dashboard, this means you do not have access to them. Contact your Writer account owner and ask to be added to their team as a developer.
SDK Example Usage
Example
import writer
s = writer.Writer(
api_key="<YOUR_API_KEY_HERE>",
organization_id=850421,
)
res = s.billing.get_subscription_details()
if res.subscription_public_response_api is not None:
# handle response
pass
Available Resources and Operations
billing
- get_subscription_details - Get your organization subscription details
ai_content_detector
- detect - Content detector api
content
- check - Check your content against your preset styleguide.
- correct - Apply the style guide suggestions directly to your content.
co_write
- generate_content - Generate content using predefined templates
- list_templates - Get a list of your existing CoWrite templates
files
models
- list - List available LLM models
completions
- create - Create completion for LLM model
- create_model_customization_completion - Create completion for LLM customization model
- stream - Create streaming completion for LLM model
model_customization
- create - Create model customization
- delete - Delete Model customization
- get - Get model customization
- list - List model customizations
download_the_customized_model
- fetch_file - Download your fine-tuned model (available only for Palmyra Base and Palmyra Large)
document
snippet
styleguide
- get - Page details
- list_pages - List your styleguide pages
terminology
user
- list - List users
Global Parameters
A parameter is configured globally. This parameter must be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set organizationId
to 99895
at SDK initialization and then you do not have to pass the same value on calls to operations like detect
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
Available Globals
The following global parameter is available. The required parameter must be set when you initialize the SDK client.
Name | Type | Required | Description |
---|---|---|---|
organization_id | int | ✔️ | The organization_id parameter. |
Example
import writer
s = writer.Writer(
api_key="<YOUR_API_KEY_HERE>",
organization_id=496531,
)
res = s.ai_content_detector.detect(content_detector_request=writer.ContentDetectorRequest(
input='<value>',
), organization_id=592237)
if res.classes is not None:
# handle response
pass
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
models.FailResponse | 400,401,403,404,500 | application/json |
models.SDKError | 4xx-5xx | / |
Example
import writer
from writer import models
s = writer.Writer(
api_key="<YOUR_API_KEY_HERE>",
organization_id=850421,
)
res = None
try:
res = s.billing.get_subscription_details()
except models.FailResponse as e:
# handle exception
raise(e)
except models.SDKError as e:
# handle exception
raise(e)
if res.subscription_public_response_api is not None:
# handle response
pass
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the server_idx: int
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://enterprise-api.writer.com |
None |
Example
import writer
s = writer.Writer(
server_idx=0,
api_key="<YOUR_API_KEY_HERE>",
organization_id=850421,
)
res = s.billing.get_subscription_details()
if res.subscription_public_response_api is not None:
# handle response
pass
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the server_url: str
optional parameter when initializing the SDK client instance. For example:
import writer
s = writer.Writer(
server_url="https://enterprise-api.writer.com",
api_key="<YOUR_API_KEY_HERE>",
organization_id=850421,
)
res = s.billing.get_subscription_details()
if res.subscription_public_response_api is not None:
# handle response
pass
Custom HTTP Client
The Python SDK makes API calls using the requests HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom requests.Session
object.
For example, you could specify a header for every request that this sdk makes as follows:
import writer
import requests
http_client = requests.Session()
http_client.headers.update({'x-custom-header': 'someValue'})
s = writer.Writer(client=http_client)
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
api_key |
apiKey | API key |
To authenticate with the API the api_key
parameter must be set when initializing the SDK client instance. For example:
import writer
s = writer.Writer(
api_key="<YOUR_API_KEY_HERE>",
organization_id=850421,
)
res = s.billing.get_subscription_details()
if res.subscription_public_response_api is not None:
# handle response
pass
Server-sent event streaming
Server-sent events are used to stream content from certain
operations. These operations will expose the stream as Generator that
can be consumed using a simple for
loop. The loop will
terminate when the server no longer has any events to send and closes the
underlying connection.
import writer
s = writer.Writer(
api_key="<YOUR_API_KEY_HERE>",
organization_id=824292,
)
res = s.completions.stream(completion_request=writer.CompletionRequest(
prompt='<value>',
best_of=1,
max_tokens=1024,
min_tokens=1,
stop=[
'the',
'is',
'and',
],
temperature=0.7,
top_p=1,
), model_id='<value>', organization_id=806561)
if res.completion_event is not None:
for event in res.completion_event:
# handle event
print(event)
SDK Generated by Speakeasy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file writerai-3.4.0.tar.gz
.
File metadata
- Download URL: writerai-3.4.0.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84aa11d444e5ab33da29b8e7c81613167aff15f2fbe49af28c11ee8abadfeb32 |
|
MD5 | 7f93a2af43bea656f80fc04d00821783 |
|
BLAKE2b-256 | 5bcbb4aa64b905f2bad4632598c0d795ee31ea65522eb0454710e7c99ce1df63 |
File details
Details for the file writerai-3.4.0-py3-none-any.whl
.
File metadata
- Download URL: writerai-3.4.0-py3-none-any.whl
- Upload date:
- Size: 106.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd740f6d48fa91564bbc89ac37cb2b97820017a1833f218a2780d1307c572ad0 |
|
MD5 | 36f075cea2b57ce8f82455c0f71c9412 |
|
BLAKE2b-256 | 68c9778d223aa39fd8f406274ee68e370916641f40567584c83fdfe5b85047ea |