Skip to main content

Auto implement function stubs

Project description

Magic Stubs

Magic Stubs implements your functions for you.

Demo

https://github.com/user-attachments/assets/f4d0fb4e-3b24-41d6-87ee-ff5931341219

Technology

MagicStubs.py uses a combination of abusing source code encodings, LLM calls, and AST rewriting so you don't have to bother writing code.

Installation

pip install magic-stubs
export OPENAI_API_KEY=...

Or see the live demo on Google Colab.

Usage

Add # coding: magic_stubs to the top of your python file. Then execute as normal. Magic Stubs will automatically fill in your function definitions where needed.

hello_world.py:

# coding: magic_stubs

def print_hello_world():
    pass

print_hello_world()
$ python3 hello_world.py 
Hello, World!

Examples

FizzBuzz

$ cat examples/fizzbuzz.py 
# coding: magic_stubs
def fizzbuzz(n):
    pass

print(' '.join([fizzbuzz(n) for n in range (1, 21)]))
$ python3 examples/fizzbuzz.py 
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz

Mandelbrot Set

$ cat examples/mandelbrot.py 
# coding: magic_stubs
def get_string_representation_of_mandelbrot_set():
    pass

print(get_string_representation_of_mandelbrot_set())
$ python3 examples/mandelbrot.py 
       
                                                                                
                                                 ***                            
                                               ******                           
                                                *****                           
                                       **   *************                       
                                        ***********************                 
                                    * ************************                  
                                    ***************************                 
                                    ****************************                
                       ********    ******************************               
                     ************ ******************************                
                     ******************************************                 
*************************************************************                   
                     ******************************************                 
                     ************ ******************************                
                       ********    ******************************               
                                    ****************************                
                                    ***************************                 
                                    * ************************                  
                                        ***********************                 
                                       **   *************                       
                                                *****                           
                                               ******                           
                                                 ***                            
        

Attribution

Inspired by and using Tsche's magic_codec.

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

magic_stubs-0.2.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

magic_stubs-0.2.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file magic_stubs-0.2.3.tar.gz.

File metadata

  • Download URL: magic_stubs-0.2.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for magic_stubs-0.2.3.tar.gz
Algorithm Hash digest
SHA256 b82733c7e2513a45f1d1728d1348bf1d58406e8b5af47ee4e128494bb11a4b02
MD5 5c6db7170c6ae1a55899c20118977f1f
BLAKE2b-256 e857b9d4b8272ed21e587ce8562a85c913ec3e19742d4cc262c4bb06bcc1662d

See more details on using hashes here.

File details

Details for the file magic_stubs-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: magic_stubs-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for magic_stubs-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f80717bdfaca8b4383541b842e8ee1b1e6e38f851453b63a8079b95e33559b88
MD5 9bec484727d6bc030923b65cd1a6b7ea
BLAKE2b-256 5d9da2ec46c39cf356e515e25fa4029f7df961cceb0445379a61c5e69748d6d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page