openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.99.7

Branches

Tags

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

Clone

HTTPS

Download ZIP

CONTRIBUTING.md

128lines · modeblame

93f3d3c3Stainless Bot2 years ago1## Setting up the environment
2
3### With Rye
4
a3001d8dStainless Bot1 years ago5We use [Rye](https://rye.astral.sh/) to manage dependencies because it will automatically provision a Python environment with the expected Python version. To set it up, run:
93f3d3c3Stainless Bot2 years ago6
a3001d8dStainless Bot1 years ago7```sh
8$ ./scripts/bootstrap
9```
10
11Or [install Rye manually](https://rye.astral.sh/guide/installation/) and run:
93f3d3c3Stainless Bot2 years ago12
13```sh
14$ rye sync --all-features
15```
16
17You can then run scripts using `rye run python script.py` or by activating the virtual environment:
18
19```sh
cca09707stainless-app[bot]1 years ago20# Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work
93f3d3c3Stainless Bot2 years ago21$ source .venv/bin/activate
22
23# now you can omit the `rye run` prefix
24$ python script.py
25```
26
27### Without Rye
28
29Alternatively if you don't want to install `Rye`, you can stick with the standard `pip` setup by ensuring you have the Python version specified in `.python-version`, create a virtual environment however you desire and then install dependencies using this command:
30
31```sh
32$ pip install -r requirements-dev.lock
33```
34
35## Modifying/Adding code
36
f6323473stainless-app[bot]1 years ago37Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
38result in merge conflicts between manual patches and changes from the generator. The generator will never
39modify the contents of the `src/openai/lib/` and `examples/` directories.
93f3d3c3Stainless Bot2 years ago40
41## Adding and running examples
42
f6323473stainless-app[bot]1 years ago43All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.
93f3d3c3Stainless Bot2 years ago44
50de514bstainless-app[bot]1 years ago45```py
93f3d3c3Stainless Bot2 years ago46# add an example to examples/<your-example>.py
47
48#!/usr/bin/env -S rye run python
49
50```
51
a3001d8dStainless Bot1 years ago52```sh
53$ chmod +x examples/<your-example>.py
93f3d3c3Stainless Bot2 years ago54# run the example against your api
a3001d8dStainless Bot1 years ago55$ ./examples/<your-example>.py
93f3d3c3Stainless Bot2 years ago56```
57
58## Using the repository from source
59
60If you’d like to use the repository from source, you can either install from git or link to a cloned repository:
61
62To install via git:
63
a3001d8dStainless Bot1 years ago64```sh
65$ pip install git+ssh://git@github.com/openai/openai-python.git
93f3d3c3Stainless Bot2 years ago66```
67
68Alternatively, you can build from source and install the wheel file:
69
70Building this package will create two files in the `dist/` directory, a `.tar.gz` containing the source files and a `.whl` that can be used to install the package efficiently.
71
72To create a distributable version of the library, all you have to do is run this command:
73
a3001d8dStainless Bot1 years ago74```sh
75$ rye build
93f3d3c3Stainless Bot2 years ago76# or
a3001d8dStainless Bot1 years ago77$ python -m build
93f3d3c3Stainless Bot2 years ago78```
79
80Then to install:
81
82```sh
a3001d8dStainless Bot1 years ago83$ pip install ./path-to-wheel-file.whl
93f3d3c3Stainless Bot2 years ago84```
85
86## Running tests
87
25cef3d9Stainless Bot2 years ago88Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
93f3d3c3Stainless Bot2 years ago89
a3001d8dStainless Bot1 years ago90```sh
93f3d3c3Stainless Bot2 years ago91# you will need npm installed
a3001d8dStainless Bot1 years ago92$ npx prism mock path/to/your/openapi.yml
93f3d3c3Stainless Bot2 years ago93```
94
a3001d8dStainless Bot1 years ago95```sh
96$ ./scripts/test
93f3d3c3Stainless Bot2 years ago97```
98
99## Linting and formatting
100
101This repository uses [ruff](https://github.com/astral-sh/ruff) and
102[black](https://github.com/psf/black) to format the code in the repository.
103
104To lint:
105
a3001d8dStainless Bot1 years ago106```sh
107$ ./scripts/lint
93f3d3c3Stainless Bot2 years ago108```
109
110To format and fix all ruff issues automatically:
111
a3001d8dStainless Bot1 years ago112```sh
113$ ./scripts/format
93f3d3c3Stainless Bot2 years ago114```
115
116## Publishing and releases
117
118Changes made to this repository via the automated release PR pipeline should publish to PyPI automatically. If
119the changes aren't made through the automated pipeline, you may want to make releases manually.
120
121### Publish with a GitHub workflow
122
25cef3d9Stainless Bot2 years ago123You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/openai/openai-python/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.
93f3d3c3Stainless Bot2 years ago124
125### Publish manually
126
c9ed0f54Stainless Bot2 years ago127If you need to manually release a package, you can run the `bin/publish-pypi` script with a `PYPI_TOKEN` set on
93f3d3c3Stainless Bot2 years ago128the environment.