pub struct PythonGenerator;Expand description
Python microservice code generator (FastAPI / Pydantic v2 / SQLAlchemy 2.0)
Implementations§
Source§impl PythonGenerator
impl PythonGenerator
Sourcepub fn generate_fastapi_service(
service_name: &str,
port: u16,
description: &str,
) -> Result<String, String>
pub fn generate_fastapi_service( service_name: &str, port: u16, description: &str, ) -> Result<String, String>
Generate a complete FastAPI service module.
The service includes:
lifespancontext manager for startup/shutdown (Armstrong let-it-crash)/healthendpoint returning{"status": "ok", "service": "<name>"}- Logging setup
- Router stub for domain routes
§Arguments
service_name- Human-readable service name, e.g."OrderService"port- Port the service listens on (used in log message only)description- One-line description embedded in the OpenAPI title
Sourcepub fn generate_pydantic_model(
model_name: &str,
fields: &[Field],
) -> Result<String, String>
pub fn generate_pydantic_model( model_name: &str, fields: &[Field], ) -> Result<String, String>
Generate a Pydantic v2 model class.
The generated model:
- Uses
model_config = {"from_attributes": True}(ORM mode) - Emits
Optional[T]with= Nonefor optional fields - Adds a
json_schema_extraexample block - Includes a
model_validatorstub for cross-field validation
§Arguments
model_name- PascalCase class name, e.g."Order"fields- Slice ofFielddescriptors
Sourcepub fn generate_sqlalchemy_repository(
model_name: &str,
fields: &[Field],
) -> Result<String, String>
pub fn generate_sqlalchemy_repository( model_name: &str, fields: &[Field], ) -> Result<String, String>
Generate a SQLAlchemy 2.0 async repository with full CRUD.
WvdA compliance: every query uses .execution_options(timeout=30) to
prevent deadlocks (boundedness guarantee).
§Arguments
model_name- PascalCase model name, e.g."Order"fields- Slice ofFielddescriptors (used to build the ORM table)
Sourcepub fn generate_pytest_tests(
service_name: &str,
endpoints: &[Endpoint],
) -> Result<String, String>
pub fn generate_pytest_tests( service_name: &str, endpoints: &[Endpoint], ) -> Result<String, String>
Generate a pytest test suite for a FastAPI service.
Produces:
@pytest.fixtureforasync_client(httpx AsyncClient)- A happy-path test and a 404 error test for each endpoint
§Arguments
service_name- Name used in test module docstringendpoints- Slice ofEndpointdescriptors
Sourcepub fn generate_requirements_txt(
service_name: &str,
features: &[&str],
) -> Result<String, String>
pub fn generate_requirements_txt( service_name: &str, features: &[&str], ) -> Result<String, String>
Generate a pinned requirements.txt for a FastAPI microservice.
Core dependencies are always included; optional feature sets are added
when the corresponding feature tag appears in features.
Recognised feature tags: "postgres", "redis", "otel", "test".
§Arguments
service_name- Used only in the header commentfeatures- Slice of feature tag strings
Auto Trait Implementations§
impl Freeze for PythonGenerator
impl RefUnwindSafe for PythonGenerator
impl Send for PythonGenerator
impl Sync for PythonGenerator
impl Unpin for PythonGenerator
impl UnsafeUnpin for PythonGenerator
impl UnwindSafe for PythonGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> EvidenceKind for T
impl<T> EvidenceKind for T
default fn kind_label(&self) -> &'static str
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more