openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.9.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

README.md

79lines · modecode

1# OpenAI Python Library
2
3The OpenAI Python library provides convenient access to the OpenAI API
4from applications written in the Python language. It includes a
5pre-defined set of classes for API resources that initialize
6themselves dynamically from API responses which makes it compatible
7with a wide range of versions of the OpenAI API.
8
9## Documentation
10
11See the [OpenAI API docs](https://beta.openai.com/docs/api-reference?lang=python).
12
13## Installation
14
15You don't need this source code unless you want to modify the package. If you just
16want to use the package, just run:
17
18```sh
19pip install --upgrade openai
20```
21
22Install from source with:
23
24```sh
25python setup.py install
26```
27
28## Usage
29
30The library needs to be configured with your account's secret key which is available on the [website](https://beta.openai.com/account/api-keys). Either set it as the `OPENAI_API_KEY` environment variable before using the library:
31
32```bash
33export OPENAI_API_KEY='sk-...'
34```
35
36Or set `openai.api_key` to its value:
37
38```python
39import openai
40openai.api_key = "sk-..."
41
42# list engines
43engines = openai.Engine.list()
44
45# print the first engine's id
46print(engines.data[0].id)
47
48# create a completion
49completion = openai.Completion.create(engine="ada", prompt="Hello world")
50
51# print the completion
52print(completion.choices[0].text)
53```
54
55### Command-line interface
56
57This library additionally provides an `openai` command-line utility
58which makes it easy to interact with the API from your terminal. Run
59`openai api -h` for usage.
60
61```
62# list engines
63openai api engines.list
64
65# create a completion
66openai api completions.create -e ada -p "Hello world"
67```
68
69## Requirements
70
71- Python 3.6+
72
73In general we want to support the versions of Python that our
74customers are using, so if you run into issues with any version
75issues, please let us know at support@openai.com.
76
77## Credit
78
79This library is forked from the [Stripe Python Library](https://github.com/stripe/stripe-python).