A modern, easy to use, Python ≥3.8 library for interacting with OBDII devices.
Python 3.8 or higher is required.
A Virtual Environment is recommended to install the library.
# Linux/macOS
python3 -m venv .venv
source .venv/bin/activate
# Windows
py -3 -m venv .venv
.venv\Scripts\activate
pip install py-obdii
# From Github
pip install git+https://github.com/PaulMarisOUMary/OBDII@main[dev,test]
# From local source
git clone https://github.com/PaulMarisOUMary/OBDII
cd OBDII
pip install .[dev,test]
# From test.pypi.org
pip install -i https://test.pypi.org/simple/ py-obdii
Important
This library is still in the design phase and may change in the future.
from obdii import at_commands, commands, Connection
conn = Connection("COM5")
version = conn.query(at_commands.VERSION_ID)
print(f"Version: {version.value}")
response = conn.query(commands.VEHICLE_SPEED)
print(f"Vehicle Speed: {response.value} {response.units}")
conn.close()
To streamline the development process, you can use the ELM327-Emulator library. This allows you to simulate an OBDII connection without needing a physical device.
-
Install the library with "dev" extra options:
pip install py-obdii[dev]
-
Start the ELM327-Emulator:
python -m elm -p "REPLACE_WITH_PORT" -s car --baudrate 38400
Note
Replace REPLACE_WITH_PORT
with the serial port of your choice
For Windows users, you can use com0com to create virtual serial ports and connect the ELM327-Emulator to your Python code.
-
Install com0com and create two virtual serial ports, (e.g.
COM5
andCOM6
). -
In the ELM327-Emulator, set the port to
COM6
. -
In your Python code, set the connection port to
COM5
.
The development of this library follows the ELM327 PDF provided by Elm Electronics, with the goal of implementing most features and commands as outlined, starting from page 6 of the document.
This library aims to deliver robust error handling, comprehensive logging, complete type hinting support, and follow best practices to create a reliable tool.
Please, feel free to contribute and share your feedback !
This library uses pytest for testing. To run the tests, you need to install the library with the [test] extra option.
-
Install the library with "test" extra options:
pip install py-obdii[test]
-
Run tests:
pytest
For questions or support, open an issue or start a discussion on GitHub. Your feedback and questions are greatly appreciated and will help improve this project !
Thank you for using or contributing to this project. Follow our updates by leaving a star to this repository !