You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pyo3 will allow us to generate an idiomatic Python implementation which is exported from Rust as a shared library.
The framework heavy-lifting will be handled completely in Rust, while the business logic will be implemented in pure Python.
Example
# Import the shared library application, context and input/output types.frompokemon_serviceimportPokemonService, SharedContextfrompokemon_service.modelimportPokemonDescriptionInput, PokemonDescriptionOutput, AuthErrorfrompokemon_service.httpimportRequest# import application specific code.from .databaseimportDatabasePool# Define a context class to be shared between handlers@dataclassclassContext:
db=DatabasePool()
# Create the application and register context. app=PokemonService()
app.context(Context())
# Define a middleware function.@app.middlewareasyncdefauth_middleware(request: Request):
ifrequest.headers.get("a-token") !="i_am_so_secret":
raiseAuthError("Invalid a-token")
# Define the operation using the type imported from Rust.@app.pokemon_descriptionasyncdefpokemon_description(input: PokemonDescriptionInput, ctx: SharedContext) ->PokemonDescriptionOutput:
description=awaitctx.db.get_description(input.name)
returnPokemonDescriptionOutput(description)
# Start the application. app.run()
Motivation and Context
Pyo3 will allow us to generate an idiomatic Python implementation which is exported from Rust as a shared library.
The framework heavy-lifting will be handled completely in Rust, while the business logic will be implemented in pure Python.
Example
Features
DateTime
type support. - Export a usable Python implementation via shared library #1476aws-smithy-types
during deserialization. - Codegenerate Python application example and add explicit cast during JSON deserialization #1520The text was updated successfully, but these errors were encountered: