Skip to content

Create a personal REST API to translate Hanzi Chinese characters to Pinyin

License

Notifications You must be signed in to change notification settings

kurt213/hanzi-pinyin-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hanzi-pinyin-api

Create a personal REST API to translate Hanzi Chinese characters to Pinyin

About

This is a simple REST API that translates Hanzi Chinese characters to Pinyin. It uses the following two sources:

Installation

  1. Clone this repository
  2. Install the requirements: pip install -r requirements.txt
  3. Create a .env file in the root directory and add the following variables:
APP_API_KEY_1=<your-api-key>:<user_alias>
APP_API_KEY_2=<your-api-key>:<user_alias>
DEEPL_API_KEY=<your-deepl-api-key>
  • replace <your-api-key> with a secure random string of your choice. This will be used to authenticate requests to the API.
  • Note: <user_alias> can be any string and can be used as an identifier of who is calling your API when looking at the API logs. e.g. 2lkmglk23m:sam
  • APP_API_KEY_2 and upwards can be used to add additional API keys. You can add as many as you like.
  • replace <your-deepl-api-key> with your created API key from DeepL.
  1. Run the app: python main.py
  2. The app will run by default on http://127.0.0.1:8000

Usage

When you run the app, you can access the API at http://127.0.0.1:8000/.

You will also need to set the request header acces_token to the value of the APP_API_KEY variable you set in the .env file.

The API has two endpoints:

  • / - returns hello world
  • /hanzi/:hanzi-string - translates a Hanzi string to Pinyin