Aython is an IPython extension that brings the power of large language models (LLMs) directly into your interactive Python sessions. Generate functions, get coding assistance, and streamline your workflow without ever leaving your terminal.
-
Install from PyPI (once published):
pip install aython
-
Or, install directly from the source for development:
pip install -e .
-
Load the extension in your IPython session:
%load_ext aython -
Set your desired LLM:
Aython uses
litellmto connect to various LLM providers. Set your model by specifying the model name.%set_model claude-3-opus-20240229Or for OpenAI:
%set_model gpt-4-turboOr for Gemini:
%set_model gemini/gemini-2.0-flash-expNote: Ensure you have the necessary API keys (e.g.,
ANTHROPIC_API_KEY,OPENAI_API_KEY) set as environment variables. -
Generate code with the
%codemagic:Describe the function you want to create, and Aython will generate it, display it for review, and load it directly into your IPython session.
%code create a function that takes a list of numbers and returns the sum of squaresAfter running the command, the generated function (e.g.,
sum_of_squares) will be available for you to use immediately.my_list = [1, 2, 3] sum_of_squares(my_list) # Output: 14
%load_ext aython: Loads the magic commands into your IPython environment.%set_model <model_name>: Sets the model to be used bylitellm.%code <description>: Takes your natural language description, sends it to the configured LLM to generate Python code, displays the code for you, and then executes it in the current session, making the new function or class immediately available.