async-openai
Unofficial Async Python client library for the OpenAI API based on Documented Specs
Features
-
Asyncio based with Sync and Async Support with
httpx -
Supports all API endpoints
-
[Images] (https://beta.openai.com/docs/api-reference/images)
-
[Search]
-
Strongly typed validation of requests and responses with
PydanticModels with transparent access to the raw response and object-based results. -
Handles Retries automatically through
backoff -
Enables Remote Cloud Object Storage File Handling through
file-io
Installation
# Install from stable
pip install async-openai
# Install from dev/latest
pip install git+https://github.com/GrowthEngineAI/async-openai.git
Quick Usage
import asyncio
from async_openai import OpenAI, settings
# Environment variables should pick up the defaults
# however, you can also set them explicitly.
# `api_key` - Your OpenAI API key. Env: [`OPENAI_API_KEY`]
# `api_base` - The base URL of the OpenAI API. Env: [`OPENAI_API_BASE`]
# `api_type` - The OpenAI API type. Env: [`OPENAI_API_TYPE`]
# `api_version` - The OpenAI API version. Env: [`OPENAI_API_VERSION`]
# `organization` - The OpenAI organization. Env: [`OPENAI_ORGANIZATION`]
# `proxies` - A dictionary of proxies to be used. Env: [`OPENAI_PROXIES`]
# `timeout_secs` - The timeout in seconds to be used. Env: [`OPENAI_TIMEOUT_SECS`]
# `max_retries` - The number of retries to be used. Env: [`OPENAI_MAX_RETRIES`]
settings.configure(
api_key = "sk-XXXX",
organization = "org-XXXX",
)
# [Sync] create a completion
# Results return a CompletionResult object
result = OpenAI.completions.create(
prompt = 'say this is a test',
max_tokens = 4,
stream = True
)
# print the completion text
# which are concatenated together from the result['choices'][n]['text']
print(result.completion_text)
# print the number of choices returned
print(len(result))
# [Async] create a completion
# All async methods are generally prefixed with `async_`
result = asyncio.run(
OpenAI.completions.async_create(
prompt = 'say this is a test',
max_tokens = 4,
stream = True
)
)
Alternative Usage
Following a similar pattern to the original openai python project, you can additionally use the methods as a drop-in replacement for most functions
import asyncio
import async_openapi as openai
# Environment variables should pick up the defaults
# however, you can also set them explicitly.
openai.settings.configure(
api_key = "sk-XXXX",
organization = "org-XXXX",
)
# [Sync] create a completion
# Results return a CompletionResult object
# Note, the only difference in this method is that the `Completion` is capitalized to match the OpenAI API
result = openai.Completions.create(
prompt = 'say this is a test',
max_tokens = 4,
stream = True
)
# print the completion text
# which are concatenated together from the result['choices'][n]['text']
print(result.completion_text)
# print the number of choices returned
print(len(result))
# [Async] create a completion
result = asyncio.run(
openai.Completions.async_create(
prompt = 'say this is a test',
max_tokens = 4,
stream = True
)
)
Dependencies
The aim of this library is to be as lightweight as possible. It is built on top of the following libraries:
Metadata
Release files for async-openai 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| async_openai-0.0.2.tar.gz | 34.3 kB | Without provenance | Details for async_openai-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| async_openai-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for async_openai-0.0.2-py3-none-any.whl |
Total release size: 76.8 kB
Release files / async_openai-0.0.2.tar.gz
| Download URL | async_openai-0.0.2.tar.gz |
|---|---|
| Size | 34.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cf77608e86d7e55d0297baaf9932ce49f791d8d417755b1d94b7ce72222525e
|
|
BLAKE2b-256 checksum How to use checksums |
7cbfd0f8acd3c2b55d69c357da77ccae10e5a913fb81e2156b64e9459fc2050c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Release files / async_openai-0.0.2-py3-none-any.whl
| Download URL | async_openai-0.0.2-py3-none-any.whl |
|---|---|
| Size | 42.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38e2b60bb0771a06fef861b95ca4a58bb899be100a84704b15c2d3b06deafce3
|
|
BLAKE2b-256 checksum How to use checksums |
14e78affb3092a87f982cb90b94bec60a2b7ff07cfad83d29186c0cf9bc7aa35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Security for async-openai 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.