diff --git a/README.md b/README.md
index 914ca6655110f5c08cca569e22c31a5890004b71..01a0eea376ee7acb436b7f57bce379baac0efbc5 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,9 @@ git clone https://github.com/uav4geo/LibreTranslate
 cd LibreTranslate
 pip install -e .
 libretranslate [args]
+
+# Or
+python main.py [args]
 ```
 
 Then open a web browser to http://localhost:5000
diff --git a/app/__init__.py b/app/__init__.py
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c28a133f2ddeffdc0599b7ecbfa4428c5b5291a9 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -0,0 +1 @@
+from .main import main
diff --git a/app/app.py b/app/app.py
index f76f9462203ba0502a393889ac817fa6d3d61415..72ec3fdfb6985f279ea8af6a744731fb24368a7d 100644
--- a/app/app.py
+++ b/app/app.py
@@ -259,6 +259,86 @@ def create_app(char_limit=-1, req_limit=-1, batch_limit=-1, ga_id=None, debug=Fa
         except Exception as e:
             abort(500, description="Cannot translate text: %s" % str(e))
 
+    @app.route("/detect", methods=['POST'])
+    def detect():
+        """
+        Detect the language of a single text
+        ---
+        tags:
+          - translate
+        parameters:
+          - in: formData
+            name: q
+            schema:
+              type: string
+              example: Hello world!
+            required: true
+            description: Text to detect
+        responses:
+          200:
+            description: Detections
+            schema:
+              id: detections
+              type: array
+              items:
+                type: object
+                properties:
+                  confidence:
+                    type: number
+                    format: float
+                    minimum: 0
+                    maximum: 1
+                    description: Confidence value
+                    example: 0.6
+                  language:
+                    type: string
+                    description: Language code
+                    example: en
+          400:
+            description: Invalid request
+            schema:
+              id: error-response
+              type: object
+              properties:
+                error:
+                  type: string
+                  description: Error message
+          500:
+            description: Detection error
+            schema:
+              id: error-response
+              type: object
+              properties:
+                error:
+                  type: string
+                  description: Error message
+          429:
+            description: Slow down
+            schema:
+              id: error-slow-down
+              type: object
+              properties:
+                error:
+                  type: string
+                  description: Reason for slow down
+        """
+        if request.is_json:
+            json = request.get_json()
+            q = json.get('q')
+        else:
+            q = request.values.get("q")
+
+        if not q:
+            abort(400, description="Invalid request: missing q parameter")
+
+        candidate_langs = list(filter(lambda l: l.lang in language_map, detect_langs(q)))
+        candidate_langs.sort(key=lambda l: l.prob, reverse=True)
+        return jsonify([{
+            'confidence': l.prob,
+            'language': l.lang
+        } for l in candidate_langs])
+
+
     @app.route("/frontend/settings")
     def frontend_settings():
         """
diff --git a/main.py b/main.py
new file mode 100644
index 0000000000000000000000000000000000000000..bf80680302adef5856d4a45d969b404360077d37
--- /dev/null
+++ b/main.py
@@ -0,0 +1,4 @@
+from app import main
+
+if __name__ == "__main__":
+    main()