Skip to main content

genfunc

PyPI version Python Support License: MIT

genfunc is a powerful Python package that leverages Large Language Models (LLMs) to automatically generate, manage, and execute Python functions. Simply describe what you want your function to do, and genfunc will create it for you.

Ideal Usecase

The ideal use case for the this package is to leverage LLMs to automatically generate, manage, and execute Python functions based on user-provided descriptions. This can be particularly useful for:

  • Rapid prototyping and development
  • Automating repetitive coding tasks
  • Generating boilerplate code
  • Creating utility functions on-the-fly
  • Enhancing productivity by reducing manual coding effort

🚀 Features

  • 🤖 Automatic function generation using state-of-the-art LLMs
  • 🔄 Support for multiple LLM providers (OpenAI, Anthropic)
  • 🔒 Secure API key handling
  • 📁 Automatic function storage and management
  • ⚡ Immediate function execution capability
  • 🛡️ Comprehensive error handling and logging
  • 🧪 Extensive test coverage

📋 Requirements

  • Python 3.8 or higher
  • Valid API key for at least one supported LLM provider (OpenAI or Anthropic)

💻 Installation

pip install genfunc

Additional Dependencies (of your choice, atleast one) -

pip install openai

or

pip install anthropic

🔧 Configuration

Before using func, you need to configure your LLM provider API keys. You have two options:

Option 1: Environment Variables

export OPENAI_API_KEY=your_openai_api_key
export ANTHROPIC_API_KEY=your_anthropic_api_key

Option 2: .env File

Create a .env file in your project root:

OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key

🎯 Quick Start

Here's a simple example to get you started:

from genfunc import func

# Initialize with OpenAI
func.initialize(provider="openai")

# Generate a function without calling it
func.generate("Create a function that calculates the factorial of a number")

# import the function 
from helpers.file_name import function_name

Alternatively,

# Generate and immediately call a function
result = func.generate(
    "Create a function that adds two numbers", 
    call=True, # calls the function
    a=5, # arg1
    b=3  # arg2
)

print(result)  # Output: 8

📖 Detailed Usage

Initialization

You can initialize func with different providers:

# Initialize with OpenAI
func.initialize(provider="openai", api_key="your_api_key")

# Initialize with Anthropic
func.initialize(provider="anthropic", api_key="your_api_key")

Function Generation

func offers two modes of function generation:

  1. Generate Only:
# This will create the function and save it to ./helpers/
func.generate("Create a function that converts temperature from Celsius to Fahrenheit")
  1. Generate and Execute:
# This will create the function, save it, and immediately execute it
result = func.generate(
    "Create a function that calculates the area of a circle",
    call=True,
    radius=5
)
print(result)  # Output: 78.53981633974483

Function Storage

Generated functions are automatically stored in the ./helpers/ directory. Each function is saved in its own Python file, making it easy to:

  • Review generated code
  • Modify functions if needed
  • Import functions into other projects
  • Version control your generated functions

Advanced Usage

Custom Provider Configuration

func.initialize(
    provider="openai",
    api_key="your_api_key",
    model="gpt-4o"  # Specify model version
)

🔍 Examples

Data Processing Function

# Generate a data processing function
func.generate("""
Create a function that takes a pandas DataFrame with columns 'date' and 'value',
and returns the moving average with a window of 7 days
""")

Algorithm Implementation

# Generate a sorting algorithm
result = func.generate(
    "Create a function that implements the quicksort algorithm",
    call=True,
    arr=[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
)
print(result)  # Output: [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]

API Integration

# Generate an API wrapper function
func.generate("""
Create a function that takes a city name and returns the current weather
using the OpenWeatherMap API
""")

View more examples here

🧪 Testing

Run the test suite:

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=func tests/

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.

View more details here

📝 License

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

🙏 Acknowledgments

  • OpenAI for their GPT models
  • Anthropic for Claude
  • All contributors who have helped shape this project

📚 Documentation

For more detailed documentation, visit our documentation site.

🤔 FAQ

Q: Is there a limit to how complex the generated functions can be?
A: The complexity limit depends on the LLM provider's token limits and capabilities. Generally, func works best with focused, single-purpose functions.

Q: Can I modify the generated functions?
A: Yes! Generated functions are stored as regular Python files in the ./helpers/ directory and can be modified like any other Python code.

Q: How secure is my API key?
A: API keys are handled securely through environment variables or .env files. They are never stored in the generated code or exposed in any way.

⚠️ Known Issues

  • Very long function descriptions might be truncated by LLM token limits
  • Some complex mathematical operations might require manual verification
  • Generated functions might need optimization for production use

🗺️ Roadmap (to-do)

  • Add support for more LLM providers
  • Implement function optimization suggestions
  • Add type hint generation
  • Create a web interface for function generation
  • Add support for async functions
  • Implement function chaining

📊 Stats

  • Release Date: 04-12-2024
  • Latest Version: 0.1.0
  • Python Versions: 3.8+

Made with ❤️ by Argish

Metadata

Release files for genfunc 0.1.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 genfunc 0.1.0
File Size Uploaded Provenance Actions
genfunc-0.1.0.tar.gz 18.4 kB Without provenance Details for genfunc-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genfunc 0.1.0
File Interpreter ABI Platform Actions
genfunc-0.1.0-py3-none-any.whl Python 3 none any Details for genfunc-0.1.0-py3-none-any.whl

Total release size: 29.7 kB

Release files / genfunc-0.1.0.tar.gz

Download URL genfunc-0.1.0.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b056138e804ed6c1c357b6d89291d729484b3eb2deb59f75ee701131bbb55832
BLAKE2b-256 checksum
How to use checksums
40aa69126a2b9f42086ef4bb81eda4bbf4122715d7c6e23de8d196139de7ff7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release files / genfunc-0.1.0-py3-none-any.whl

Download URL genfunc-0.1.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a3cc88010683e1c2db373868f39e0aaca90907eddf78b265c618a06f3c03f95
BLAKE2b-256 checksum
How to use checksums
8b69a3640d8135207f7e8e075e93f6a19ff101f42ad0f2b6ddc64567b9e25bb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Security for genfunc 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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