1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-11-17 21:10:12 +01:00
LibreTranslate/main.py

32 lines
1.5 KiB
Python
Raw Permalink Normal View History

2020-12-19 23:40:37 +01:00
import argparse
2020-12-20 21:05:22 +01:00
from app.app import create_app
2020-12-19 23:40:37 +01:00
parser = argparse.ArgumentParser(description='LibreTranslate - Free and Open Source Translation API')
2020-12-20 20:03:53 +01:00
parser.add_argument('--host', type=str,
help='Hostname (%(default)s)', default="127.0.0.1")
parser.add_argument('--port', type=int,
help='Port (%(default)s)', default=5000)
2020-12-20 22:57:31 +01:00
parser.add_argument('--char-limit', default=-1, type=int, metavar="<number of characters>",
2020-12-20 20:03:53 +01:00
help='Set character limit (%(default)s)')
2020-12-20 21:05:22 +01:00
parser.add_argument('--req-limit', default=-1, type=int, metavar="<number>",
help='Set maximum number of requests per minute per client (%(default)s)')
2020-12-20 21:52:02 +01:00
parser.add_argument('--ga-id', type=str, default=None, metavar="<GA ID>",
2020-12-20 20:03:53 +01:00
help='Enable Google Analytics on the API client page by providing an ID (%(default)s)')
2020-12-20 21:05:22 +01:00
parser.add_argument('--debug', default=False, action="store_true",
help="Enable debug environment")
parser.add_argument('--ssl', default=None, action="store_true",
help="Whether to enable SSL")
2020-12-20 20:03:53 +01:00
2020-12-19 23:40:37 +01:00
args = parser.parse_args()
if __name__ == "__main__":
2020-12-20 21:05:22 +01:00
app = create_app(char_limit=args.char_limit,
req_limit=args.req_limit,
2020-12-20 21:52:02 +01:00
ga_id=args.ga_id,
2020-12-20 21:05:22 +01:00
debug=args.debug)
if args.debug:
app.run(host=args.host, port=args.port)
else:
from waitress import serve
serve(app, host=args.host, port=args.port, url_scheme='https' if args.ssl else 'http')