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