Skip to main content

Seatools FastAPI Starter

This framework must be used in conjunction with the seatools-starter-server-* packages, using seatools-starter-server-uvicorn as an example here.

中文文档

Usage Guide

  1. Install with poetry add fastapi seatools-starter-server-uvicorn seatools-starter-web-fastapi
  2. Configure config/application.yml as follows:
seatools:
  server:
    # Here are the uvicorn parameter configurations
    uvicorn:
      host: 0.0.0.0
      port: 8000
      workers: 1
      reload: true
  # Here are the FastAPI configurations
  fastapi:
    title: xxxxx
    description: xxx
    docs_url: none
  1. Usage, load by defining ioc container functions
from seatools.ioc import Autowired, Bean
from fastapi import FastAPI


app = Autowired(cls=FastAPI)

# Add middleware

from fastapi.middleware.cors import CORSMiddleware
    
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Add global exception handler
# Custom exception handling
@app.exception_handler(AssertionError)
async def assert_exception_handler(request, exc):
    ...

# Add route method
@app.get('/')
async def hello():
    return "hello"

# Add route
from fastapi import APIRouter
custom_router = APIRouter(prefix='/custom')

@custom_router.get('/')
async def custom_hello():
    return "custom hello"

@Bean
def register_custom_router(app: FastAPI):
    app.include_router(custom_router)

# FastAPI integration with seatools ioc injection
@Bean
class ServiceA:
    
    async def hello(self):
        return "serviceA"


@app.get('/serviceA')
async def serviceA(serviceA = Autowired(cls=ServiceA)): # Inject seatools.ioc in the controller parameter using Autowired, note that the type should not be explicitly declared here, FastAPI will fail on parameter type checking for unsupported types
    return await serviceA.hello()
    
# Or inject at the router level, this method is more recommended
@app.get('/serviceA')
async def serviceA():
    serviceA = Autowired(cls=ServiceA)
    return await serviceA.hello()
  1. Run, see seatools-starter-server-*, example seatools-starter-server-uvicorn

Metadata

Release files for seatools-starter-web-fastapi 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seatools-starter-web-fastapi 1.0.3
File Size Uploaded Provenance Actions
seatools_starter_web_fastapi-1.0.3.tar.gz 3.1 kB Without provenance Details for seatools_starter_web_fastapi-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for seatools-starter-web-fastapi 1.0.3
File Interpreter ABI Platform Actions
seatools_starter_web_fastapi-1.0.3-py3-none-any.whl Python 3 none any Details for seatools_starter_web_fastapi-1.0.3-py3-none-any.whl

Total release size: 7.3 kB

Release files / seatools_starter_web_fastapi-1.0.3.tar.gz

Download URL seatools_starter_web_fastapi-1.0.3.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
83006bc4dc483bd8c2e744b339966ae53de9b8536b8b290ee450d3959c8f17f8
BLAKE2b-256 checksum
How to use checksums
82a8e62063b944e9855e00300ad66233e07b8987d5147b8866c5f5b0c5f58946
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / seatools_starter_web_fastapi-1.0.3-py3-none-any.whl

Download URL seatools_starter_web_fastapi-1.0.3-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2dcb86700dc70b60fc07cb4abe4f2ded6761e27f13aa584e644efad9ec3ed7b
BLAKE2b-256 checksum
How to use checksums
5ea8f0b73c70a9f7a2ef673ba7ae336c8d5f94ba06a0a0c87038d9160bb88225
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for seatools-starter-web-fastapi 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page