Skip to main content

Import wisdom, export code.

Project description

AutoGenLib

The only library you'll need ever.

Import wisdom, export code.

AutoGenLib is a Python library that automatically generates code on-the-fly using OpenAI's API. When you try to import a module or function that doesn't exist, AutoGenLib creates it for you based on a high-level description of what you need.

Features

  • Dynamic Code Generation: Import modules and functions that don't exist yet
  • Context-Aware: New functions are generated with knowledge of existing code
  • Progressive Enhancement: Add new functionality to existing modules seamlessly
  • Persistent Storage: Generated code is cached for future use
  • Full Codebase Context: LLM can see all previously generated modules for better consistency

Installation

pip install autogenlib

Or install from source:

git clone https://github.com/cofob/autogenlib.git
cd autogenlib
pip install -e .

Requirements

  • Python 3.12+
  • OpenAI API key

Quick Start

Set OpenAI API key in OPENAI_API_KEY env variable.

from autogenlib import init
init("Library for generating secure random tokens")

# Import a function that doesn't exist yet - it will be automatically generated
from autogenlib.tokens import generate_token

# Use the generated function
token = generate_token(length=32)
print(token)

How It Works

  1. You initialize AutoGenLib with a description of what you need
  2. When you import a module or function under the autogenlib namespace, the library:
    • Checks if the module/function already exists
    • If not, it sends a request to OpenAI's API with your description
    • The API generates the appropriate code
    • The code is validated, cached, and executed
    • The requested module/function becomes available for use

Examples

Generate a TOTP Generator

from autogenlib import init
init("Library for generating TOTP codes")
from autogenlib.totp import totp_generator
print(totp_generator("SECRETKEY123"))

Add a Verification Function Later

# Later in your application, you need verification:
from autogenlib.totp import verify_totp
result = verify_totp("SECRETKEY123", "123456")
print(f"Verification result: {result}")

Create Multiple Modules

from autogenlib import init
init("Cryptographic utility library")

# Generate encryption module
from autogenlib.encryption import encrypt_text, decrypt_text
encrypted = encrypt_text("Secret message", "password123")
decrypted = decrypt_text(encrypted, "password123")
print(decrypted)

# Generate hashing module
from autogenlib.hashing import hash_password, verify_password
hashed = hash_password("my_secure_password")
is_valid = verify_password("my_secure_password", hashed)
print(f"Password valid: {is_valid}")

Configuration

Setting the OpenAI API Key

Set your OpenAI API key as an environment variable:

export OPENAI_API_KEY="your-api-key-here"
# Optional
export OPENAI_API_BASE_URL="https://openrouter.ai/api/v1"  # Use OpenRouter API
export OPENAI_API_KEY="openai/gpt-4.1"

Or in your Python code (not recommended for production):

import os
os.environ["OPENAI_API_KEY"] = "your-api-key-here"

Cache Location

By default, generated code is cached in ~/.autogenlib_cache. You can check this directory to see what has been generated.

Limitations

  • Requires internet connection to generate new code
  • Depends on OpenAI API availability
  • Generated code quality depends on the clarity of your description
  • Not suitable for production-critical code without review

Advanced Usage

Inspecting Generated Code

You can inspect the code that was generated for a module:

from autogenlib.totp import totp_generator
import inspect
print(inspect.getsource(totp_generator))

How AutoGenLib Uses the OpenAI API

AutoGenLib creates prompts for the OpenAI API that include:

  1. The description you provided
  2. Any existing code in the module being enhanced
  3. The full context of all previously generated modules
  4. The specific function or feature needed

This comprehensive context helps the LLM generate code that's consistent with your existing codebase.

Contributing

Contributions are not welcome! This is just a fun PoC project.

License

MIT License


Note: This library is meant for prototyping and experimentation. Always review automatically generated code before using it in production environments. Note: Of course 100% of the code of this library was generated via LLM

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

autogenlib-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autogenlib-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file autogenlib-0.1.0.tar.gz.

File metadata

  • Download URL: autogenlib-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.29

File hashes

Hashes for autogenlib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 255dce82398e559d16ce63277c031fc76ad0f3315b3f84da27be6a9430090d1d
MD5 59bb99362880eb2d319fb037e7aecef5
BLAKE2b-256 c0e118f5f3286f71c6fe06a395644991bf61b96c8a5b3781bc675f88ef7d2d50

See more details on using hashes here.

File details

Details for the file autogenlib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autogenlib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.29

File hashes

Hashes for autogenlib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db4ec2acf3ad041e1dd13d4e3dbd6da487dcaa8d1d8f6e34551e319966f4c7df
MD5 1c8a6104d015abefc2d47bae3a068d5c
BLAKE2b-256 ae094011628f348eed9683d2a83d15de2e8e6505bb796cb718478a4f2f22cd8f

See more details on using hashes here.

Supported by

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