Pythoness: use natural language to define Python functions.
Project description
Pythoness
Pythoness: The priestess of the oracle of Apollo at Delphi.
by Emery Berger
Pythoness is a Python module that automatically generates Python code based on natural language descriptions of the desired functionality.
NOTE: To use pythoness, you must first set up an OpenAI API key. If you
already have an API key, you can set it as an environment variable
called OPENAI_API_KEY
. If you do not have one yet,
you can get a key here: https://platform.openai.com/account/api-keys
export OPENAI_API_KEY=<your-api-key>
Installation
The easiest way to install Pythoness is through pip:
python3 -m pip install pythoness
Usage
To use Pythoness, you just import the pythoness
module and then use the @pythoness.spec
decorator to specify the desired functionality. Here is an:
import pythoness
@pythoness.spec("Compute the nth number in the Fibonacci series.")
def myfib(n: int) -> int:
""
This code will generate a Python function named myfib
that computes the nth number in the Fibonacci series.
To actually execute the function, you can call it as you would any other Python function:
for i in range(20):
print(myfib(i))
Pythoness caches the results of translating natural language to Python, so subsequent executions in the same directory will run much faster.
If you want Pythoness to replace the code with the generated function, just add replace=True
:
@pythoness.spec("Compute the nth number in the Fibonacci series.", replace=True)
def myfib(n: int) -> int:
""
Setting the replace
flag will cause Pythoness to rewrite the program with the synthesized function definition(s).
Project details
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
Hashes for pythoness-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70ff4f61248c40613f9814a51cd2417b7073c6172c08cebb477ade23d670e4e2 |
|
MD5 | b721eca34bfe28263d0b3a587054b553 |
|
BLAKE2b-256 | eaee8b8221f6ba205cd281af0c2e6a8786f1778dbb891fc11b9dc0d1ee3ac4f6 |