OpenAPI Python Generator

The OpenAPI Python Generator tool creates Python FastAPI server code based on your OpenAPI specification 3.0 specification. This code helps you quickly scaffold API endpoints that are defined in your OpenAPI document so that you can focus on implementing business logic instead of writing boilerplate code.

Important: Ensure that you have created OpenAPI document beforehand.
Key highlights
  • Generates a Python FastAPI backend server based on an input OpenAPI 3.0 specification.
  • Supports generation of three different server types:
    • Simple Server for mocking API responses.
    • Database creates, retrieve, update, and delete Server for direct database interactions.
    • Connector Pack Server for interacting with the IBM Connectivity Pack applications.
The following operations are supported in the OpenAPI Python Generator tool:
Table 1. Parameters
Parameter Required Description Default
input_file Yes The OpenAPI Specification in YAML or JSON format. None
server_type No The server type that you want to generate. Blank (indicating a simple server type)
database_type No The database language type that you want to use when generating the database CRUD type server Postgres

Simple server

A minimalist server that provides the basic setup to start building your service.

Example prompt
Generate some Python FastAPI server code based on the following openapi @<filename.yaml>

Database CRUD server

An extension of the Simple Server that incorporates database logic to perform create, read, update, and delete (CRUD) operations, directly on your own database. This type is suitable for applications that require persistent data management. You can also specify a database language to use by default Postgres is used to but you can also use DynamoDB and Db2.

Example prompts
Generate some Python FastAPI server with database interaction code based on the following openapi @<filename.yaml>

Generate some Python FastAPI server with postgres database interaction code based on the following openapi @<filename.yaml>

Generate some Python FastAPI server with dynamodb database interaction code based on the following openapi @<filename.yaml>

Generate some Python FastAPI server with db2 database interaction code based on the following openapi @<filename.yaml>

Connector Pack server

The Connector Pack server variant is designed to generate code for integrating with the IBM Connectivity Pack. Start by using OASCreator Tool to craft a tailored OpenAPI 3.0 specification for this server type. This code generation allows to provide important information that is required for connector application generation. From that specification, the generator produces both a FastAPI backend and a Client SDK library that handles all communication with the IBM Connectivity Pack endpoint.

The following IBM Connectivity Pack applications are supported:
  • Postgres
  • DynamoDB
  • Db2
  • Salesforce
  • ServiceNow
Example prompts
Generate some Python FastAPI server for a connector based on the following openapi @<filename.yaml>

Generate some Python FastAPI server for a postgres connector based on the following openapi @<filename.yaml>

Generate some Python FastAPI server for a dynamodb connector based on the following openapi @<filename.yaml>

Generate some Python FastAPI server for a db2 connector based on the following openapi @<filename.yaml>

Generate some Python FastAPI server for a salesforce connector based on the following openapi @<filename.yaml>

Generate some Python FastAPI server for a servicenow connector based on the following openapi @<filename.yaml>
Important:
  1. The IBM Connectivity Pack Connector URL is automatically filled into your generated config.json. This route has whitelisted APIs that only allow applications that have been deployed on the IBM managed Code Engine instance to call it. You will not be able to make local API Calls to this route.
  2. For the applications supported by the API Agent you must bring your own credentials to make API calls to the IBM Connectivity Pack route provided. These credentials must be inputted into the generated config.json. The credentials setup varies between applications.