Quickstart
This quickstart helps you go from an OpenAPI file to a running local API using Alpha. A working example of the code generated in this quickstart can be found in the example folder of the Alpha repository.
What you will build
By the end of this page, you will have:
- Alpha installed with API generation support
- a minimal OpenAPI specification
- generated API code in an
api/folder - a local development server running on
http://localhost:8080
Prerequisites
- Python 3.11+
uv(for this example, but you can use any Python environment manager)
1. Create a project structure
Create a new directory for your project, navigate into it and initialize a new project:
Add the alpha dependencies to your project:
Create the folders used by the generator:
Create specification/openapi.yaml and add a minimal API:
openapi: 3.0.0
info:
title: <project_name> API
version: 0.1.0
servers:
- url: http://localhost:8080
paths:
/:
get:
operationId: health_check
x-alpha-custom-function: 'dict(status="ok")'
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: ok
2. Generate API code
Run the generator in development mode:
What this does:
- reads
specification/openapi.yaml - generates (or updates) code in
api/ - starts a watch loop so changes in the spec are re-generated automatically
If you only want to generate once:
Install the generated API package in your environment in editable mode:
3. Implement business logic
Create at least the following files:
src/<project_name>/containers/__init__.pysrc/<project_name>/containers/container.pysrc/<project_name>/__init__.py
With the following content:
In src/<project_name>/containers/container.py:
from dependency_injector import containers, providers
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
In src/<project_name>/__init__.py:
from <project_name>.containers.container import Container
def init_container() -> Container:
container = Container()
container.wire(modules=[__name__])
return container
4. Run the API
In a second terminal:
The generated API should now be available at http://localhost:8080.
The Swagger UI should be available at http://localhost:8080/ui.
5. Test your endpoint
Use curl to verify everything works:
Expected response:
{
"data": {
"status": "ok"
},
"detail": "OK",
"status": 200,
"title": "OK",
"type": "application/json"
}
6. Iterate quickly
Keep both commands running during development:
uv run alpha api gen(watch mode)uv run alpha api run
Then update your OpenAPI file and implement business logic in the generated service layer.
Next steps
- Learn how to design your application architecture in the Design Principles guide
- Learn how to implement business logic in the Dependency Injection guide
- Continue with the full API Generation guide
- Add authentication via Authentication guide
- Add persistence via Database interaction guide