Skip to main content

Fawern AI, A Python Developer AI Assistant

Project description

fawern

fawern is a Python library designed to assist developers with various AI-powered tools for code generation, analysis, refactoring, and more. It utilizes advanced models to provide a wide range of functionalities, from generating Python code based on prompts to analyzing and fixing code, generating documentation, and even converting code from other languages to Python.

Features

  • ChatPython: Generate Python code based on a given input prompt.
  • CodeAnalyzer: Analyze, refactor, and optimize Python code.
  • CodeFormatter: Format Python code according to PEP8 standards.
  • ErrorLogAnalyzer: Log and analyze Python errors, providing suggestions for fixes.
  • CodeReviewer: Review Python code and provide feedback on structure, clarity, and quality.
  • DocumentationGenerator: Generate detailed docstrings and inline comments for Python code.
  • ConvertToPython: Convert code from other programming languages to Python.
  • CodeVisualizer: Generate visual representations such as flowcharts or class diagrams for Python code.
  • BugFixer: Automatically identify and fix bugs in Python code.
  • UnitTestGenerator: Generate unit tests for Python code to ensure correctness.

Installation

You can install Fawern using pip:

pip install fawern

Usage

ChatPython

Generate Python code based on a prompt:

from fawern import ChatPython

assistant = ChatPython()

prompt = '''Create a snake game using Pygame. Include a snake that moves around the screen and eats food. Display the score and end the game when the snake collides with the wall or itself. Use arrow keys to control the snake' movement '''

code = assistant.generate_code(prompt)

print(code)

This will generate Python code for a snake game using Pygame based on the given prompt. To write the generated code to a file, you can use the following code:

assistant.write_code_to_file(path='./')

This will write the generated code to a file named generated_file_name.py in the current directory. You can use run_generated_code() method to run the generated code:

assistant.run_generated_code()

This will run the generated code using the Python interpreter.

CodeAnalyzer

Here's an example of how to use the CodeAnalyzer feature to analyze and refactor Python code:

from fawern import CodeAnalyzer

analyzer = CodeAnalyzer()

code = """
def add_numbers(a, b):
    return a + b

print(add_numbers(5, '10'))
"""

# Analyze the code
analysis = analyzer.analyze_code(code)
print(analysis)

# Find and fix syntax errors
fixed_code = analyzer.find_syntax_errors(code)
print(fixed_code)

# Suggest optimizations
optimizations = analyzer.suggest_optimizations(code)
print(optimizations)

This will analyze the given Python code, find syntax errors, and suggest optimizations to improve the code.

CodeFormatter

Format Python code according to PEP8 standards:

from fawern import CodeFormatter

formatter = CodeFormatter()

code = """
def addNumbers(a,b):
    return a + b
"""

# Format the code
formatted_code = formatter.format_code(code)
print(formatted_code)

This will format the given Python code according to PEP8 standards.

ErrorLogAnalyzer

Log and analyze Python errors, providing suggestions for fixes:

from fawern import ErrorLogAnalyzer

error_analyzer = ErrorLogAnalyzer()

# Log an error
error_message = "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
error_analyzer.log_error(error_message)

# Analyze logged errors
analysis = error_analyzer.analyze_errors()
print(analysis)

This will log the given error message and analyze it to provide suggestions for fixes.

CodeReviewer

Review Python code and provide feedback on structure, clarity, and quality:

from fawern import CodeReviewer

reviewer = CodeReviewer()

code = """
def add_numbers(a, b):
    return a + b
"""

# Review the code
review = reviewer.review_code(code)
print(review)

This will review the given Python code and provide feedback on its structure, clarity, and quality.

DocumentationGenerator

Generate detailed docstrings and inline comments for Python code:

from fawern import DocumentationGenerator

doc_generator = DocumentationGenerator()

code = """
def add_numbers(a, b):
    return a + b
"""

# Generate docstrings and comments
documentation = doc_generator.generate_docstrings(code)
print(documentation)

This will generate detailed docstrings and inline comments for the given Python code.

ConvertToPython

Convert code from other programming languages to Python:

from fawern import ConvertToPython

converter = ConvertToPython()

java_code = """
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
"""

# Convert Java code to Python
python_code = converter.convert_code(java_code)
print(python_code)

This will convert the given Java code to Python code.

CodeVisualizer

Generate visual representations such as flowcharts or class diagrams for Python code:

from fawern import CodeVisualizer

visualizer = CodeVisualizer()

code = """
class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        pass

class Dog(Animal):
    def speak(self):
        return "Woof!"

class Cat(Animal):
    def speak(self):
        return "Meow!"
"""

# Visualize the code
visualization = visualizer.visualize_code(code)
print(visualization)

This will generate a class diagram for

BugFixer

Automatically identify and fix bugs in Python code:

from fawern import BugFixer

bug_fixer = BugFixer()

code = """
def add_numbers(a, b):
    return a + b

print(add_numbers(5, '10'))
"""

# Fix bugs in the code
fixed_code = bug_fixer.fix_bugs(code)
print(fixed_code)

This will automatically identify and fix bugs in the given Python code.

UnitTestGenerator

Generate unit tests for Python code to ensure correctness:

from fawern import UnitTestGenerator

test_generator = UnitTestGenerator()

code = """
def add_numbers(a, b):
    return a + b
"""

# Generate unit tests for the code
unit_tests = test_generator.generate_tests(code)
print(unit_tests)

This will generate unit tests for the given Python code to ensure its correctness.

Contributing

Contributions are welcome! But fawern is not public yet. We will make it public soon.

License

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

Acknowledgements

  • This project was inspired by the need for AI-powered tools to assist developers in various aspects of software development.

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

fawern-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

fawern-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file fawern-0.1.1.tar.gz.

File metadata

  • Download URL: fawern-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for fawern-0.1.1.tar.gz
Algorithm Hash digest
SHA256 019c70f2ad0494ad60258c30111a7d213468dd6498f8b49b89b0ee3bf99fe5fc
MD5 d94c87da924f3baba9dec169eca8504d
BLAKE2b-256 e8c6744f1e852ee38c50f894590b8ca7d4c25ef6c0e33280da38b40b85d064e2

See more details on using hashes here.

File details

Details for the file fawern-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fawern-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for fawern-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 964319d19ec4a3083c9b613c3520e49d9c288dcfd1e48169f5c011e28b1753b6
MD5 51af8847bed63c2a9a6344e7ac5843ec
BLAKE2b-256 364d06913794d87f499b16a75b2cda10a345496d9bc9b396c90691d311068dec

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