A Flask-based REST API for university rankings data, providing comprehensive information about universities, their rankings across various sources, and supporting multiple languages (English and Chinese).
- University Data: Access detailed information about universities worldwide
- Multi-source Rankings: Rankings from QS, US News, Niche, and other sources
- Multilingual Support: University names available in both English and Chinese
- Flexible Filtering: Search and filter universities by various criteria
- Ranking Details: Detailed ranking information by source and subject
- Dropdown Data: Country, city, and ranking options for UI components
- Python 3.8+
- SQLite3
-
Clone the repository:
git clone <repository-url> cd University_Ranking_Backend
-
Install dependencies:
pip install -r requirements.txt
-
Ensure the database file
University_rankings.dbis in the project root directory. -
Run the application:
python app.py
The API will be available at http://localhost:10000
Filter and search universities with optional ranking sorting.
Query Parameters:
query(optional): Search term for university namesort_credit(optional): Ranking table name for sorting (default: "US_News_best global universities_Rankings")country(optional): Filter by countrycity(optional): Filter by city
Example:
curl "http://localhost:10000/universities/filter?query=harvard&country=United%20States"Response:
[
{
"id": 1,
"normalized_name": "harvard-university",
"name": "Harvard University",
"country": "United States",
"city": "Cambridge",
"photo": "harvard.jpg",
"rank_value": 1,
"chinese_name": "哈佛大学"
}
]Get detailed information about a specific university by ID.
Example:
curl "http://localhost:10000/universities/1"Response:
{
"id": 1,
"normalized_name": "harvard-university",
"name": "Harvard University",
"country": "United States",
"city": "Cambridge",
"photo": "harvard.jpg",
"chinese_name": "哈佛大学",
"rankings": [
{
"subject": "Overall",
"source": "QS",
"rank_value": 5
}
],
"stats": [
{
"type": "undergraduate_enrollment",
"count": 6700,
"year": 2023
}
]
}Get university information by normalized name.
Example:
curl "http://localhost:10000/universities/harvard-university"Get university rankings from a specific source.
Example:
curl "http://localhost:10000/universities/harvard-university/rankings/QS"Response:
{
"university": {
"name": "Harvard University",
"country": "United States",
"city": "Cambridge",
"photo": "harvard.jpg",
"chinese_name": "哈佛大学"
},
"source": "QS",
"rankings": [
{
"subject": "Overall",
"rank_value": 5
}
]
}Get university name in specified language.
Query Parameters:
language: Language code (enfor English,zhfor Chinese, default:en)
Example:
# Get Chinese name
curl "http://localhost:10000/universities/translate/harvard-university?language=zh"
# Get English name
curl "http://localhost:10000/universities/translate/harvard-university?language=en"Response:
{
"normalized_name": "harvard-university",
"language": "zh",
"name": "哈佛大学"
}Get list of all available countries.
Example:
curl "http://localhost:10000/dropdown/countries"Response:
[
"United States",
"United Kingdom",
"Canada"
]Get cities for a specific country.
Query Parameters:
country: Country name
Example:
curl "http://localhost:10000/dropdown/cities?country=United%20States"Response:
[
"Cambridge",
"New York",
"Berkeley"
]Get available ranking options, optionally filtered by source and subject.
Query Parameters:
source(optional): Filter by ranking sourcesubject(optional): Filter by subject
Example:
# Get all ranking options
curl "http://localhost:10000/dropdown/ranking_options"
# Filter by source
curl "http://localhost:10000/dropdown/ranking_options?source=QS"Response:
[
{
"table": "QS_World_University_Rankings_2024",
"source": "QS",
"subject": "Overall",
"top_universities": [
{
"normalized_name": "harvard-university",
"rank_value": 5,
"name": "Harvard University",
"chinese_name": "哈佛大学"
}
]
}
]Get detailed ranking information for a specific table, source, and subject.
Query Parameters:
table: Ranking table name (required)source: Ranking source (required)subject: Ranking subject (required)
Example:
curl "http://localhost:10000/subject_rankings/ranking_detail?table=QS_World_University_Rankings_2024&source=QS&subject=Overall"Response:
[
{
"normalized_name": "harvard-university",
"rank_value": 5,
"name": "Harvard University",
"chinese_name": "哈佛大学"
},
{
"normalized_name": "stanford-university",
"rank_value": 6,
"name": "Stanford University",
"chinese_name": "斯坦福大学"
}
]The application uses SQLite database with the following main tables:
id: Primary keynormalized_name: Normalized university name (URL-friendly)name: Full university namecountry: Country locationcity: City locationphoto: Photo filename
id: Foreign key to Universities.idenglish_name: English namechinese_name: Chinese translation
Dynamic tables for different ranking sources (e.g., QS_World_University_Rankings_2024):
normalized_name: Foreign key to Universities.normalized_namesource: Ranking sourcesubject: Ranking subject/categoryrank_value: Numerical ranking
normalized_name: Foreign key to Universities.normalized_nametype: Statistic typecount: Statistic valueyear: Year of statistic
University_Ranking_Backend/
├── app.py # Main Flask application
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── University_rankings.db # SQLite database
├── models/ # Data models
│ ├── universities.py
│ ├── university.py
│ ├── translations.py
│ ├── ranking_options.py
│ ├── countries.py
│ ├── cities.py
│ └── ranking_options.py
├── routes/ # API route handlers
│ ├── universities.py
│ ├── dropdown.py
│ └── ranking_detail.py
├── scripts/ # Data processing scripts
└── data/ # Raw data files
- Create or modify route handlers in
routes/ - Implement business logic in
models/ - Register blueprints in
app.py - Update this README
The scripts/ directory contains utilities for:
- Processing ranking data from various sources
- Generating translations
- Populating the database
The API returns appropriate HTTP status codes:
200: Success400: Bad Request (missing parameters)404: Not Found (university or resource not found)
Error responses include a JSON object with an error field describing the issue.
The API includes CORS support for cross-origin requests, making it suitable for web applications.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Copyright (C) <2025> <Ruize Xia>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.