Links
- Documentation: Docs
- Repository: GitHub
- PyPi: FastOpenAPI
About a month ago, I decided to share my project, FastOpenAPI, with the Hacker News community. FastOpenAPI is a library designed to simplify working with OpenAPI schemas and integrating them with various Python frameworks. My goal was to create a user-friendly solution, inspired by FastAPI, for developers using Falcon, AioHTTP, Tornado, and other popular frameworks.
Why did I create FastOpenAPI?
If you've ever had to maintain API documentation for multiple Python frameworks simultaneously, you know how cumbersome it can be. Each framework often requires a unique approach. Appreciating FastAPI’s simplicity and intuitive design, I wanted to bring that same convenience and efficiency to other platforms.
How does FastOpenAPI work?
FastOpenAPI acts as a universal layer providing consistent creation and validation of OpenAPI schemas across multiple frameworks. It implements a unified interface alongside tools to streamline integration, documentation, and data validation.
Request processing flow in FastOpenAPI:
Receiving Request
- The client sends an HTTP request to a specific route.
- The web framework (Flask, Falcon, AioHTTP, Starlette, Sanic, Quart, Tornado) receives the request.
Forwarding Request
- The framework delegates the request to the handler registered by FastOpenAPI.
- The router extracts URL path parameters, query parameters, and the request body (JSON).
Validating Data
- The router analyzes the signature of the user-defined function.
- Input data is transformed based on type annotations.
- Pydantic models (if used) are validated.
Calling User Function
- The router passes validated arguments to the user-defined function, supporting synchronous and asynchronous operations.
Handling Result
- The function returns a result.
- The router serializes the result, especially for Pydantic models, and adds metadata like HTTP status codes.
Forming Response
- The router converts the serialized result into a format compatible with the specific framework.
- The framework sends back an HTTP response.
Handling Errors
- Any exceptions are caught by the router.
- Errors are standardized into a JSON response with an appropriate HTTP status code.
This architecture provides:
- Consistent route definitions across frameworks.
- Automatic validation and transformation of data.
- Standardized error handling.
- Automatic OpenAPI documentation generation.
The core of FastOpenAPI allows developers to concentrate on business logic instead of worrying about integration specifics.
Community Feedback and Improvements
I shared FastOpenAPI on Hacker News to get constructive criticism and recommendations, a platform known for its candid and professional audience.
My post received a very positive response: it remained on the front page for over 12 hours, garnered approximately 150 upvotes, and sparked valuable discussions. The community suggested essential improvements, such as:
- Class-level schema caching for better performance.
- Standardized error handling.
- Support for basic Python data types as response models.
Version 0.5.0 – A Major Milestone
Thanks to community feedback, version 0.5.0 featured highly anticipated enhancements:
- Integration with AioHTTP.
- Implementation of class-level schema caching.
- Improved error handling mechanisms.
- Support for simple data types as response models.
- Comprehensive documentation overhaul (fastopenapi.fatalyst.dev).
A significant pull request also ensured consistent use of aliases from Pydantic during serialization and schema generation.
The community response surpassed my expectations, providing actionable suggestions and motivating further project development.
What's next?
Future releases will focus on simplifying the API, removing deprecated solutions, enhancing performance, and expanding framework support. Continuous documentation improvements and more usage examples will remain a priority.
Acknowledgments
I'm incredibly grateful to everyone who participated in discussions on Hacker News and other platforms. Your valuable contributions have significantly improved FastOpenAPI, reinforcing my belief in the strength and future of open source communities!