# Get Alliance Color The ``DriverStation`` class ([Java](https://github.wpilib.org/allwpilib/docs/beta/java/org/wpilib/driverstation/DriverStation.html), [C++](https://github.wpilib.org/allwpilib/docs/beta/cpp/classwpi_1_1_driver_station.html), :py:class:`Python `) has many useful features for getting data from the Driver Station computer. One of the most important features is ``getAlliance`` (Java & Python) / ``GetAlliance`` (C++). Note that there are three cases: red, blue, and no color yet. It is important that code handles the third case correctly because the alliance color will not be available until the Driver Station connects. In particular, code should not assume that the alliance color will be available during constructor methods or `robotInit`, but it should be available by the time `autoInit` or `teleopInit` is called. FMS will set the alliance color automatically; when not connected to FMS, the alliance color can be set from the Driver Station (see :ref:`"Team Station" on the Operation Tab `). ## Getting your Alliance Color and Doing an Action .. tab-set-code:: ```java Optional ally = DriverStation.getAlliance(); if (ally.isPresent()) { if (ally.get() == Alliance.Red) { } if (ally.get() == Alliance.Blue) { } } else { } ``` ```c++ using wpi::DriverStation::Alliance; if (auto ally = wpi::DriverStation::GetAlliance()) { if (ally.value() == Alliance::kRed) { } if (ally.value() == Alliance::kBlue) { } } else { } ``` ```Python from wpilib import DriverStation ally = DriverStation.getAlliance() if ally is not None: if ally == DriverStation.Alliance.kRed: elif ally == DriverStation.Alliance.kBlue: else: ```