Skip to content

A restful API tool based on FastAPI to communicate with tango device & db, including APIs for reading and modifying attributes, adding, deleting, modifying and checking properties, command, etc. Contains the functions of the original jive and reset server

Notifications You must be signed in to change notification settings

Contemporaries/Tango-rest-server-fastapi

Repository files navigation

TO DO (MCP Server)Under development

There is already a FastAPI to MCP project https://github.com/tadata-org/fastapi_mcp, which can be directly applied Consider directly integrating MCP with Tango server

Connect to MCP (Model Context Protocol) and drive it with a large model Test Result: Screenshot 2025-04-15 160102

Tango REST API based on FastAPI

A REST API service based on FastAPI and PyTango for interacting with Tango devices.

System Requirements

  • Python 3.8+
  • Tango server environment

Installation

  1. Clone the repository:
git clone https://github.com/Contemporaries/Tango-rest-server-fastapi.git
cd Tango-rest-server-fastapi
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # Linux/Mac
# or
.venv\Scripts\activate  # Windows
  1. Install dependencies:
pip install -r requirements.txt

API Doc

http(s)://your_host:8000/docs

Project Structure

IHEP-Tango-Rest-API/
├── assets/          # Static resource files
├── config/          # Configuration files
│   ├── env_config.py   # Environment variable configuration
│   ├── log_config.py   # Log configuration
├── controller/      # API controllers
│   ├── controller_attribute.py   # Attribute-related interfaces
│   ├── controller_command.py     # Command-related interfaces
│   ├── controller_db.py         # Database-related interfaces
│   ├── controller_info.py       # Information query interfaces
│   ├── controller_polling.py    # Polling-related interfaces
│   └── controller_property.py   # Property configuration interfaces
|   └── controller_env.py       # Environment variable interfaces
├── exception/       # Exception handling
├── model/          # Data models
├── service/        # Business logic layer
│   ├── service_attribute.py     # Attribute services
│   ├── service_command.py       # Command services
│   ├── service_db.py           # Database services
│   ├── service_info.py         # Information query services
│   ├── service_polling.py      # Polling services
│   └── service_property.py     # Property configuration services
│   └── service_env.py       # Environment variable services
├── test/           # Test files
├── tools/          # Utility functions
├── enums/          # Enum definitions
├── main.py         # Application entry point
└── requirements.txt # Project dependencies
└── .env            # Environment variables

Development Guide

1. Adding New APIs

  1. Create a new controller file in the controller directory
  2. Implement business logic in the service directory
  3. Register the route in main.py

2. Error Handling

Use GlobalException for unified error handling:

from exception.global_exception import GlobalException

try:
    # Business logic
except Exception as e:
    raise GlobalException(str(e))

3. Response Model

Use ResponseModel to ensure a unified response format:

from model.response_models import ResponseModel

return ResponseModel(
    code: int
    success: bool
    message: str | None = None
    data: dict | str | list | int | bool | None = None
)

About

A restful API tool based on FastAPI to communicate with tango device & db, including APIs for reading and modifying attributes, adding, deleting, modifying and checking properties, command, etc. Contains the functions of the original jive and reset server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages