※当サイトの記事には、広告・プロモーションが含まれます。

PythonでMVC構成の際にアプリケーションサーバーの要否はどうなっているのか

nazology.net

⇧ 恐怖でしかないんだけど...
狂気としか言いようがない...

MVC(Model View Controller)とは

Wikipediaによると、

Model-View-Controller (MVC、モデル・ビュー・コントローラ) はUIを持つソフトウェアに適用されるソフトウェアアーキテクチャの一種である。

Model View Controller - Wikipedia

MVCはソフトウェアを処理/Model・表示/View・入力伝達/Controllerの3要素に分割し、ソフトウェア内部データをユーザーが直接参照・編集する情報から分離する。プレゼンテーション(View・Controller)とドメイン(Model)を分離しまたユーザー入力(Controller)と表示(View)も分離することでソフトウェアの保守性・開発生産性を向上させる。

Model View Controller - Wikipedia

⇧ とありますと。

基本的に、サーバーサイド側は、MVC構成を取ることが多いように思う、JavaSpring Frameworkとか使ってる場合だと、Spring Web MVCというものが用意されているぐらいなので、一般的なのかなと。

Spring BootではTomcatというアプリケーションサーバーが内蔵されている

で、JavaSpring Frameworkとかと一緒にSpring Bootとか使うことが多いと思うのだけど、Spring Bootは、Apcahe Tomcatというアプリケーションサーバーが組み込まれていますと。

stackoverflowによると、

stackoverflow.com

SpringBoot embeds Apache Tomcat which starts when the application registers one or more Spring Controller. Apache listens on a given port (default 8080) which can be customised, also HTTPS can be enabled, and routes the incoming request to the controllers (according to path configuration).

https://stackoverflow.com/questions/64282838/how-tomcat-or-any-server-pass-the-request-to-the-spring-boot

⇧ 上記のように、Spring Bootに内蔵されているTomcatが8080ポートでHTTPリクエストを受け付けるようになっていますと。

Springの公式なブログによると、

spring.io

⇧ Spring Web MVCは、Apache TomcatServlet engine上で動作するとなっているので、アプリケーションサーバーが必要であると。

つまり、少なくとも、JavaSpring FrameworkでSpring Web MVCとか使ってMVC構成を実現するには、アプリケーションサーバーが必要であると。

PythonMVC構成の際にアプリケーションサーバーの要否はどうなっているのか

で、ようやっと、本題。

PythonメインのWebアプリケーション開発において、MVC構成を実現する際は、アプリケーションサーバーの要否ってどうなのか?

一応、ネットの情報だと、

www.linuxlinks.com

Pythonにもアプリケーションサーバーは存在するらしい。

なるほど、

blog.devgenius.io

PythonのWebフレームワークには詳しくは無いのだけど、PythonにおいてもMVC構成を実現する一般的な方法としては、アプリケーションサーバーが必要であるという理解で良さそうと。

何やら、

qiita.com

⇧ Node.js + Python-shell という方法で、HTTPリクエストを処理したりもできるそうな。

ただ、Pythonで一般的なMVC構成を実現するにあたっては、Python用のアプリケーションサーバーを用意するで良さそうってことですかね?

PythonのWebフレームワークは、何を使ったら良いんだろうか?

とりあえず、

www.linkedin.com

⇧ 上記サイト様の投稿によると、「Instagram」は「Django」というPython用のWebフレームワークを利用していると。

ただ、

gustavwillig.medium.com

⇧「FastAPI」というフレームワークの利用者数の上昇率が気になりますな...

何やら、

qiita.com

⇧ 上記サイト様で、パフォーマンスの比較をしており、新規での開発だと「FastAPI」を利用していった方が良さそうってことですかね。

そもそもとして、

は何なのか?

WSGI(Web Server Gateway Interface)

The Web Server Gateway Interface (WSGI, pronounced whiskey or WIZ-ghee) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0.1, is specified in Python Enhancement Proposal (PEP) 3333.

https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface

■ASGI(Asynchronous Server Gateway Interface)

The Asynchronous Server Gateway Interface (ASGI) is a calling convention for web servers to forward requests to asynchronous-capable Python frameworks, and applications. It is built as a successor to the Web Server Gateway Interface (WSGI).

https://en.wikipedia.org/wiki/Asynchronous_Server_Gateway_Interface

⇧ とあり、インターフェイスであると。

そうなってくると、JavaにおけるApache Tomcatのような「アプリケーションサーバー」とは異なるんでは?

blowup-bbs.com

特徴

WEBサーバのインターフェイスのイメージ図 | Blow Up By Black Swan

⇧ 一応、「アプリケーションサーバー」という扱いで良いと。

一応、「アプリケーションサーバー」の定義を確認。

An application server is a server that hosts applications or software that delivers a business application through a communication protocol.

For a typical web application, the application server sits behind the web servers.

https://en.wikipedia.org/wiki/Application_server

An application server framework is a service layer model. It includes software components available to a software developer through an application programming interface. An application server may have features such as clusteringfail-over, and load-balancing. The goal is for developers to focus on the business logic.

https://en.wikipedia.org/wiki/Application_server

⇧とあり、「アプリケーションサーバー」には様々な機能があるものの、最低限「アプリケーション」と通信できる機能があれば良さそうってことですかね?

そういった意味では、Pythonで利用されている、

の機能を含んでいるらしい、

あたりは「アプリケーションサーバー」と捉えても良いということですかね?

毎度モヤモヤ感が半端ない…

今回はこのへんで。