[PYTHON] Create API using hug with mod_wsgi

hug is a module that makes it easy to create APIs in Python. mod_wsgi is a package for running Python code with Apache. By combining these, you can easily create an API that runs on Apache.

Load hug application with mod_wsgi

You need to have an application that supports WSGI in your Python code. application is prepared in hug, and it can be read as follows.

Sample code

# -*- coding:utf-8 -*-

import hug

@hug.get("/", examples="text=Hello World!")
def keyword_extraction_api(text: hug.types.text):
    return {'text': text}

application = __hug_wsgi__

Now send a request with http://hoge-server.com/text=Hello%20World! and you will get{"text": "Hello World!"}.

A little addicted

I was addicted to the fact that I couldn't execute the code. The cause is that I wrote __hug_wsgi__ first. (Maybe writing a decorator will add a method to __hug_wsgi__? So it would be nice to write __hug_wsgi__ at the end.)

Recommended Posts

Create API using hug with mod_wsgi
Create an API with Django
Create Awaitable with Python / C API
[AWS] Create API with API Gateway + Lambda
Create API with Python, lambda, API Gateway quickly using AWS SAM
Create a CRUD API using FastAPI
Automatically create Python API documentation with Sphinx
Try using Dropbox API v2 with Go
Create an application using the Spotify API
[Python] Quickly create an API with Flask
Create Page / Todo Block with Notion API
Play with puns using the COTOHA API
Automatic follow-back using streaming api with Tweepy
[AWS SAM] Create API with DynamoDB + Lambda + API Gateway
Easy to create API server using go-json-rest module
Let's create a REST API using SpringBoot + MongoDB
Create an API server quickly with Python + Falcon
Create an app that works well with people's reports using the COTOHA API
Try to make RESTful API with MVC using Flask 1.0.2
Register a ticket with redmine API using python requests
Create a tweet heatmap with the Google Maps API
Extrude with Fusion360 API
Create a pseudo REST API server using GitHub Pages
Create games with Pygame
Create filter with scipy
How to analyze with Google Colaboratory using Kaggle API
Get tweets with arbitrary keywords using Twitter's Streaming API
Create a company name extractor with python using JCLdic
[LINE Messaging API] Create parrot return BOT with Python
Build a web API server at explosive speed using hug
Image recognition with API from zero knowledge using AutoML Vision
Create a real-time auto-reply bot using the Twitter Streaming API
Tornado-Let's create a Web API that easily returns JSON with JSON
Create a web API that can deliver images with Django
Create playlists of bright songs only with Spotify Web API
Create a social integration API for smartphone apps with Django
Play with YouTube Data API v3 using Google API Python Client
Using X11 with ubuntu18.04 (C)
Image download with Flickr API
Create an application that just searches using the Google Custom Search API with Python 3.3.1 in Bottle
Use Trello API with python
When using optparse with iPython
Try using PythonTex with Texpad.
Create an environment with virtualenv
Using Graphviz with Jupyter Notebook
Create "Typoglycemia" sentences using COTOHA
Create Cloud TPU with tf-nightly
Draw hello world with mod_wsgi
Messaging with AMQP using kombu
Create / search / create table with PynamoDB
Test CloudStack API Using Simulator
Use Twitter API with Python
Using Quaternion with Python ~ numpy-quaternion ~
Try using matplotlib with PyCharm
Age recognition using Pepper's API
Create 3d gif with python3
API with Flask + uWSGI + Nginx
Games using IMU with SenseHat
Create graph with plotly button
[Python] Using OpenCV with Python (Basic)
Try using the Twitter API