Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Client API Spec

From Leeroopedia
Knowledge Sources
Domains Simulation, Autonomous Driving, API Specification
Last Updated 2026-02-15 05:00 GMT

Overview

YML specification file that defines the carla.Client class API, which connects to the CARLA simulator server and provides methods for world management, batch commands, and recording/replaying.

Description

This YML file is the canonical API specification for the Client class, which is the primary entry point for interacting with the CARLA simulator. The Client connects to the RPC server running the simulation. Key methods include __init__ (accepting host, port, worker_threads), apply_batch and apply_batch_sync (for executing lists of commands in a single simulation step), generate_opendrive_world (loading maps from OpenDRIVE strings), load_world (switching maps by name), and reload_world (resetting the current map). The Client also manages the recording feature, which saves simulation data for replay. Multiple clients can connect simultaneously, though walker management may cause conflicts across clients.

Usage

Use this specification when establishing connections to the CARLA server, managing worlds, executing batch commands, or working with the recorder. It is consumed by doc_gen.py to produce API reference documentation.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/docs/client.yml

Signature

- module_name: carla
  classes:
  - class_name: Client
    methods:
    - def_name: __init__
      params:
      - param_name: host          # type: str, default: '127.0.0.1'
      - param_name: port          # type: int, default: 2000
      - param_name: worker_threads # type: int, default: 0
    - def_name: apply_batch
      params:
      - param_name: commands      # type: list
    - def_name: apply_batch_sync
      params:
      - param_name: commands      # type: list
      - param_name: due_tick_cue  # type: bool, default: false
      return: list(command.Response)
    - def_name: generate_opendrive_world
    - def_name: load_world
    - def_name: reload_world

Import

import carla
client = carla.Client('127.0.0.1', 2000)

I/O Contract

Parameter Type Default Description
host str '127.0.0.1' IP address of the CARLA server
port int 2000 TCP port of the CARLA server
worker_threads int 0 Background worker threads (0 = use all available)
Method Return Description
apply_batch(commands) None Execute batch commands without response
apply_batch_sync(commands, due_tick_cue) list(command.Response) Execute batch commands with response
load_world(map_name) None Load a new map, destroying current actors
reload_world() None Reload current map with default settings
generate_opendrive_world(opendrive) None Load world from OpenDRIVE string

Usage Examples

import carla

# Connect to the simulator
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

# Load a map
client.load_world('Town01')

# Get the world
world = client.get_world()

# Batch spawn vehicles
blueprints = world.get_blueprint_library().filter('vehicle.*')
spawn_points = world.get_map().get_spawn_points()
batch = [carla.command.SpawnActor(bp, sp) for bp, sp in zip(blueprints, spawn_points)]
results = client.apply_batch_sync(batch, True)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment