Skip to main content

Shell 🐢 Craft 🪡

PyPI version codecov

Generating shell commands and code using natural language models (OpenAI ChatGPT).

Shell Craft can:

  1. Generate shell commands from natural language requests.
  2. Write code in a dozen languages from natural language requests.
  3. Refactor existing code.
  4. Document existing code.
  5. Generate tests for existing code.
  6. Generate issue tickets and feature requests for GitHub, GitLab, and BitBucket.

Our goal is to 10x developer productivity by combining the power of natural language models with the power of the command line.

Installation

See the Wiki for installation instructions.

Command Line Interface

Shell Craft often follows the format of:

shell-craft --prompt <type> <request>

You can use the following command to get started:

shell-craft --help

See the Wiki for additional command line usage instructions.

See Prompt Types for a guide to the different --prompt options.

Python API

The following example shows how to use Shell Craft inside of your own Python code. The example loads your api key from an environment variable, uses the Bash prompt, and gets input from the user.

import os

from shell_craft.services import OpenAIService, OpenAISettings
from shell_craft.prompts import BASH_PROMPT

results = OpenAIService(
    OpenAISettings(
        api_key = os.environ.get("OPENAI_API_KEY"),
        model='gpt-3.5-turbo',
        count=1,
        temperature=0.0,
        messages=BASH_PROMPT.messages,
    )
).query(
    message = input("Enter your request: ")
)

print(results)

API Key

Shell Craft uses the OpenAI API to generate the shell commands, requiring an API key to give it access to an account with OpenAI.

Warning! API keys are sensitive information and should be kept confidential. Don't share your API key with anyone who shouldn't have access to it. Failure to do so may result in charges on your OpenAI account. Shell Craft never transmits this key to any service other than the official OpenAI API. Your API key is your responsibility.

To obtain an API key from the OpenAI platform, follow these steps:

  1. Go to https://platform.openai.com/account/api-keys in your web browser.
  2. Log in to your OpenAI account or create a new account if you don't have one.
  3. Click the "Create new secret key" button.
  4. Copy the key that is generated for you.

Once you have your API key, you must pass it to Shell Craft via one of the following methods.

Option 1 (Recommended) - Configuration file:

shell-craft looks for a configuration file in the following places, in order:

  • the current directory, named config.json
  • the file named by $SHELLCRAFT_CONFIG
  • $XDG_CONFIG_HOME/shell-craft/config.json
  • $HOME/.config/shell-craft/config.json

The contents are simple json:

{
    "openai_api_key": "<your secret key>"
}

Now, Shell Craft will know your API key in order to run future prompts without having to specify it or ensure it exists in the environmental variables.

Option 2 - Command Line Argument:

shell-craft "list all files in directory" --api-key API_KEY

Where API_KEY is your OpenAI API key.

Option 3 - Environment Variable:

export OPENAI_API_KEY=<your secret key>
shell-craft "list all files in directory"

Where <your secret key> is your OpenAI API key.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Acknowledgments contain a few of the people who have helped the project along the way.

  • OpenAI for their language models and API.
  • Joel Fourhman for the initial idea, the challenge, and the project name.
  • Chase Montgomery for testing, feedback, and estimated time savings vs manual implementation.
  • Bryan Gonzalez for powershell feedback and merge reviews.
  • Aaron Croissette for business use case feedback, documentation, and a lovely PyPi icon on the readme.

Release files for openai-shell-craft 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-shell-craft 1.2.0
File Size Uploaded
openai_shell_craft-1.2.0.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-shell-craft 1.2.0
File Interpreter ABI Platform
openai_shell_craft-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.2 kB

Release files / openai_shell_craft-1.2.0.tar.gz

Download URL openai_shell_craft-1.2.0.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
963e29d1fff0b4a8b7c160c1858037ca7075e866f09c16785a8ac37c3ee0b2c1
BLAKE2b-256 checksum
How to use checksums
25fffb8fe638b1f602fc13922febb179a6c0f07484a58ccffb17ca677fbbe856
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / openai_shell_craft-1.2.0-py3-none-any.whl

Download URL openai_shell_craft-1.2.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43c59c044d9e6747d0821f09fc5e80fc119b85f685ef107f1e6afedd59b3facd
BLAKE2b-256 checksum
How to use checksums
a8975336ef906f567e9ad29a0dd0b9ce7e9baf734157b70e955d39bf953c7312
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page