A professional Python package for generating code with Google Gemini via LangChain.
This repository is focused on a clean code generation package and deployment-ready examples.
Included in this repository:
codegen/— reusable package with Gemini integration, prompt generation, validation, and auto-fix support.codegen_demo.py— polished command-line demo showcasing package usage.app_fastapi.py— REST API for remote code generation.app_streamlit.py— interactive Streamlit UI for generation, validation, and runtime execution.Dockerfile— container image definition for production deployment.Procfile— process configuration for platform deployment..env.example— environment variable template.
Install the package in editable mode:
pip install -e .Or install dependencies directly:
pip install -r requirements.txtCopy .env.example to .env and add your Gemini API key:
copy .env.example .envSet one of the following environment variables:
GOOGLE_API_KEYGEMINI_API_KEY
python codegen_demo.pyThe package exposes a CLI entrypoint named codegen:
codegen "generate a Python function that reverses a list" --validate --auto-fixStart the API locally:
uvicorn app_fastapi:app --host 0.0.0.0 --port 8000Example request body:
{
"task": "generate a Python helper that removes duplicates from a list",
"language": "python",
"style": "idiomatic",
"include_docstrings": true,
"include_type_hints": true,
"validate": true,
"auto_fix": false
}Run the interactive front-end:
streamlit run app_streamlit.pyBuild and run the container:
docker build -t codegen-app .
docker run -p 8000:8000 --env-file .env codegen-appThe Procfile is included to support deployment on process-based platforms.
codegen/llm_client.py— Gemini LLM abstraction with retries and structured logging.codegen/prompts.py— prompt builder for generation and examples.codegen/generator.py— code generation, validation, and auto-fix workflow.codegen/sandbox.py— safe Python execution sandbox.codegen/cli.py— CLI wrapper.app_fastapi.py— FastAPI application entrypoint.app_streamlit.py— Streamlit application entrypoint.codegen_demo.py— polished demo script.
- Keep secret keys out of source control and never commit
.env. - Use
python -m venv .venvfor isolated development. - Update dependencies carefully when changing LangChain or Gemini SDK versions.