|
| 1 | +# Antares Python Client |
| 2 | + |
| 3 | +[](https://github.com/TheSoftwareDesignLab/ANTARES/actions/workflows/python-ci.yml) |
| 4 | +[](https://github.com/TheSoftwareDesignLab/ANTARES) |
| 5 | +[](https://pypi.org/project/antares-python/) |
| 6 | +[](LICENSE) |
| 7 | + |
| 8 | +> ✨ A modern Python interface for the Antares simulation engine ✨ |
| 9 | +
|
| 10 | +Antares Python Client is a developer-friendly library and CLI tool that allows you to interact with the Antares simulation engine via HTTP and TCP protocols. |
| 11 | + |
| 12 | +- Provides a high-level Python API to control the simulation |
| 13 | +- Automatically maps Python objects to Antares-native requests |
| 14 | +- Supports configuration via `.env` and `.toml` files |
| 15 | +- Offers a CLI for scripting and manual control |
| 16 | +- Built with Pydantic 2, Typer, and fully type-annotated |
| 17 | + |
| 18 | +Inspired by tools like PySpark, this library acts as a thin but powerful façade over the Antares backend. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 🌟 Features |
| 23 | + |
| 24 | +- Add ships with complex motion patterns to the simulation |
| 25 | +- Subscribe to live simulation events over TCP |
| 26 | +- Launch the Antares binary locally with config |
| 27 | +- Configure everything via `.env` or `.toml` |
| 28 | +- Clean CLI with rich output and JSON support |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## 🚀 Installation |
| 33 | + |
| 34 | +### Requirements |
| 35 | + |
| 36 | +- Python >= 3.13 (tested with 3.13) |
| 37 | +- `uv` for isolated dev environments |
| 38 | + |
| 39 | +### Install from PyPI |
| 40 | + |
| 41 | +```bash |
| 42 | +pip install antares-python |
| 43 | +``` |
| 44 | + |
| 45 | +### Install in editable mode (for development) |
| 46 | + |
| 47 | +```bash |
| 48 | +git clone https://github.com/TheSoftwareDesignLab/ANTARES.git |
| 49 | +cd ANTARES/antares-python |
| 50 | +uv venv |
| 51 | +source .venv/bin/activate |
| 52 | +uv pip install -e . |
| 53 | +``` |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## 🚧 CLI Usage (`antares-cli`) |
| 58 | + |
| 59 | +After installing, the CLI tool `antares-cli` becomes available. |
| 60 | + |
| 61 | +### Available Commands |
| 62 | + |
| 63 | +| Command | Description | |
| 64 | +|---------------|--------------------------------------------------| |
| 65 | +| `add-ship` | Add a ship with specific motion type | |
| 66 | +| `reset` | Reset the simulation | |
| 67 | +| `subscribe` | Subscribe to simulation event stream | |
| 68 | +| `start` | Start the Antares binary with optional config | |
| 69 | + |
| 70 | +### Common Options |
| 71 | + |
| 72 | +| Option | Description | |
| 73 | +|---------------|-------------------------------------------------| |
| 74 | +| `--config` | Path to `.toml` config file | |
| 75 | +| `--verbose` | Enable detailed output | |
| 76 | +| `--json` | Output results in JSON format | |
| 77 | + |
| 78 | +Example: |
| 79 | + |
| 80 | +```bash |
| 81 | +antares-cli add-ship --type line --x 0 --y 0 --angle 0.5 --speed 5.0 |
| 82 | +``` |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## 📚 Python Usage Example |
| 87 | + |
| 88 | +```python |
| 89 | +import asyncio |
| 90 | +from antares.client import AntaresClient |
| 91 | +from antares.models.ship import LineShip, CircleShip, RandomShip, StationaryShip |
| 92 | +from antares.models.track import Track |
| 93 | + |
| 94 | + |
| 95 | +async def main(): |
| 96 | + # Create the Antares client using environment config or .env file |
| 97 | + client = AntaresClient() |
| 98 | + |
| 99 | + # Define ships of each supported type |
| 100 | + ships = [ |
| 101 | + StationaryShip(initial_position=(0.0, 0.0), type="stationary"), |
| 102 | + RandomShip(initial_position=(10.0, -10.0), max_speed=15.0, type="random"), |
| 103 | + CircleShip(initial_position=(-30.0, 20.0), radius=25.0, speed=3.0, type="circle"), |
| 104 | + LineShip(initial_position=(5.0, 5.0), angle=0.78, speed=4.0, type="line"), |
| 105 | + ] |
| 106 | + |
| 107 | + # Add each ship to the simulation |
| 108 | + for ship in ships: |
| 109 | + client.add_ship(ship) |
| 110 | + print(f"✅ Added {ship.type} ship at {ship.initial_position}") |
| 111 | + |
| 112 | + print("\n📡 Subscribing to simulation events...\n") |
| 113 | + |
| 114 | + # Listen to simulation events (TCP stream) |
| 115 | + async for event in client.subscribe(): |
| 116 | + if isinstance(event, Track): |
| 117 | + print( |
| 118 | + f"📍 Track #{event.id} - {event.name} at ({event.lat}, {event.long}) → {event.speed} knots" |
| 119 | + ) |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + # Run the main async function |
| 124 | + asyncio.run(main()) |
| 125 | +``` |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## 🧭 Ship Types |
| 130 | + |
| 131 | +Ships are classified based on their motion pattern. The `type` field determines which parameters are required. Here's a summary: |
| 132 | + |
| 133 | +| Type | Required Fields | Description | |
| 134 | +|-------------|---------------------------------------------|---------------------------------------------| |
| 135 | +| `stationary`| `initial_position` | Does not move at all | |
| 136 | +| `random` | `initial_position`, `max_speed` | Moves randomly, up to a max speed | |
| 137 | +| `circle` | `initial_position`, `radius`, `speed` | Moves in a circular pattern | |
| 138 | +| `line` | `initial_position`, `angle`, `speed` | Moves in a straight line | |
| 139 | + |
| 140 | +Each ship type corresponds to a specific Pydantic model: |
| 141 | + |
| 142 | +- `StationaryShip` |
| 143 | +- `RandomShip` |
| 144 | +- `CircleShip` |
| 145 | +- `LineShip` |
| 146 | + |
| 147 | +You can also use the generic `ShipConfig` union to parse from dynamic input like TOML or JSON. |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## ⚙️ Configuration |
| 152 | + |
| 153 | +The client supports two configuration methods: |
| 154 | + |
| 155 | +### `.env` File |
| 156 | + |
| 157 | +The `.env` file allows you to define environment variables: |
| 158 | + |
| 159 | +```dotenv |
| 160 | +ANTARES_HOST=localhost |
| 161 | +ANTARES_HTTP_PORT=9000 |
| 162 | +ANTARES_TCP_PORT=9001 |
| 163 | +ANTARES_TIMEOUT=5.0 |
| 164 | +ANTARES_AUTH_TOKEN= |
| 165 | +``` |
| 166 | + |
| 167 | +➡️ See `template.env` for a complete example. |
| 168 | + |
| 169 | +### `.toml` Config File |
| 170 | + |
| 171 | +To configure the client and ships via a TOML file: |
| 172 | + |
| 173 | +```toml |
| 174 | +[antares] |
| 175 | +host = "localhost" |
| 176 | +http_port = 9000 |
| 177 | +tcp_port = 9001 |
| 178 | +timeout = 5.0 |
| 179 | +auth_token = "" |
| 180 | + |
| 181 | +[[antares.ships.stationary]] |
| 182 | +initial_position = [50.0, 50.0] |
| 183 | + |
| 184 | +[[antares.ships.random]] |
| 185 | +initial_position = [-20.0, 20.0] |
| 186 | +max_speed = 10.0 |
| 187 | + |
| 188 | +[[antares.ships.circle]] |
| 189 | +initial_position = [30.0, -30.0] |
| 190 | +radius = 20.0 |
| 191 | +speed = 4.0 |
| 192 | + |
| 193 | +[[antares.ships.line]] |
| 194 | +initial_position = [0.0, 0.0] |
| 195 | +angle = 0.785 |
| 196 | +speed = 5.0 |
| 197 | +``` |
| 198 | + |
| 199 | +➡️ See `config.example.toml` for a full working example. |
| 200 | + |
| 201 | +You can pass the config to any CLI command with: |
| 202 | + |
| 203 | +```bash |
| 204 | +antares-cli add-ship --config path/to/config.toml |
| 205 | +``` |
| 206 | + |
| 207 | +Or use it in Python with: |
| 208 | + |
| 209 | +```python |
| 210 | +from antares.config_loader import load_config |
| 211 | +settings = load_config("config.toml") |
| 212 | +``` |
| 213 | + |
| 214 | +--- |
| 215 | + |
| 216 | +## 🧪 Development & Testing |
| 217 | + |
| 218 | +This project uses modern Python tooling for fast, isolated, and productive workflows. |
| 219 | + |
| 220 | +### Setup |
| 221 | + |
| 222 | +```bash |
| 223 | +uv venv |
| 224 | +source .venv/bin/activate |
| 225 | +uv pip install -e .[dev] |
| 226 | +``` |
| 227 | + |
| 228 | +### Available Tasks (via [`task`](https://taskfile.dev)) |
| 229 | + |
| 230 | +| Task | Description | |
| 231 | +|----------------|---------------------------------------------| |
| 232 | +| `task check` | Run linters (ruff, mypy) and formatter check | |
| 233 | +| `task test` | Run full test suite | |
| 234 | +| `task format` | Auto-format code with ruff + black | |
| 235 | +| `task build` | Build the wheel and source dist | |
| 236 | +| `task publish` | Publish to PyPI (requires version bump) | |
| 237 | + |
| 238 | +### Run tests manually |
| 239 | + |
| 240 | +```bash |
| 241 | +pytest |
| 242 | +``` |
| 243 | + |
| 244 | +### View test coverage |
| 245 | + |
| 246 | +```bash |
| 247 | +pytest --cov=antares --cov-report=term-missing |
| 248 | +``` |
| 249 | + |
| 250 | +--- |
| 251 | + |
| 252 | +## 📄 License |
| 253 | + |
| 254 | +This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details. |
| 255 | + |
| 256 | +--- |
| 257 | + |
| 258 | +## 🤝 Contributing |
| 259 | + |
| 260 | +Contributions are welcome! To contribute: |
| 261 | + |
| 262 | +1. Fork the repository |
| 263 | +2. Create a new branch (`git checkout -b feature/my-feature`) |
| 264 | +3. Make your changes |
| 265 | +4. Run `task check` and `task test` to ensure quality |
| 266 | +5. Submit a pull request 🚀 |
| 267 | + |
| 268 | +For significant changes, please open an issue first to discuss what you’d like to do. |
| 269 | + |
| 270 | +Happy hacking! 🛠️ |
0 commit comments