Implementation:CARLA simulator Carla Python Client Bindings
| Knowledge Sources | |
|---|---|
| Domains | Python Bindings, Client Connection |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
Boost.Python binding file that exposes the CARLA Client class and OpenDRIVE generation parameters to the Python API.
Description
This file defines the export_client() function that registers the Client class and OpendriveGenerationParameters with Boost.Python. The Client class is constructed with host, port, and worker thread count, and provides methods for connection management (set_timeout, get_client_version, get_server_version), world management (get_world, load_world, reload_world, load_world_if_different, generate_opendrive_world), map queries (get_available_maps), file management (set_files_base_folder, get_required_files, request_file), recording and replay (start_recorder, stop_recorder, show_recorder_file_info, replay_file, stop_replayer), and batch command execution (apply_batch, apply_batch_sync). The ApplyBatchCommandsSync helper function handles multi-threaded processing of batch responses and autopilot registration through the Traffic Manager. OpendriveGenerationParameters exposes vertex_distance, max_road_length, wall_height, additional_width, and junction smoothing options.
Usage
This binding is the primary entry point for Python scripts connecting to a CARLA server. Every CARLA Python application begins by constructing a carla.Client to establish communication with the simulator.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/carla/src/Client.cpp
Signature
void export_client();
// Key classes exposed:
class_<cc::Client>("Client",
init<std::string, uint16_t, size_t>(
(arg("host")="127.0.0.1", arg("port")=2000, arg("worker_threads")=0u)))
class_<rpc::OpendriveGenerationParameters>("OpendriveGenerationParameters",
init<double, double, double, double, bool, bool, bool>())
Import
import carla
client = carla.Client('localhost', 2000)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| host | str | Yes | IP address of CARLA server (default: 127.0.0.1) |
| port | int | Yes | TCP port of CARLA server (default: 2000) |
| worker_threads | int | No | Number of worker threads (default: 0) |
| seconds | float | Yes (for set_timeout) | Timeout duration in seconds |
| map_name | str | Yes (for load_world) | Name of the map to load |
Outputs
| Name | Type | Description |
|---|---|---|
| world | carla.World | Handle to the simulation world |
| available_maps | list[str] | List of available map names |
| client_version | str | Client API version string |
| server_version | str | Server API version string |
Usage Examples
import carla
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
print(client.get_client_version())
print(client.get_server_version())
# Load a specific map
client.load_world('Town03')
world = client.get_world()
# Batch spawn
batch = [carla.command.SpawnActor(bp, t) for bp, t in zip(blueprints, transforms)]
responses = client.apply_batch_sync(batch, True)