Async OUI Lookups
aiooui offers an asynchronous approach to perform Organisationally Unique Identifier (OUI) lookups, enabling efficient identification of vendors based on MAC addresses in Python applications. It supports asynchronous programming models, making it suitable for use in modern Python asynchronous frameworks. The current version is 0.1.9, with a fairly active release cadence, frequently publishing minor updates and bug fixes.
Common errors
-
aiooui.exceptions.OUIError: Failed to load OUI data
cause The OUI data file could not be downloaded or accessed, potentially due to network issues, file permissions, or an unsupported environment (e.g., Windows pathing issues in older versions).fixEnsure an active internet connection. If on Windows, update `aiooui` to the latest version (`pip install --upgrade aiooui`). Check your Python environment's permissions for writing to the package's data directory. -
RuntimeError: Event loop is closed
cause Attempting to run `aiooui`'s asynchronous functions outside of a running asyncio event loop, or after the loop has been explicitly closed, commonly occurs when mixing sync and async code improperly or when the event loop lifecycle isn't managed correctly.fixAlways execute `aiooui` methods within an `async` function and run it using `asyncio.run(your_async_function())`. Avoid calling `await` outside an `async` context. If using a framework, ensure proper integration with its async features.
Warnings
- gotcha On Windows systems, `aiooui` has historically faced issues loading OUI data due to pathing or permissions. Ensure your environment allows the library to download and access necessary data files.
- gotcha The library fetches OUI data from external sources. Intermittent network issues or server unavailability during installation or initial usage can lead to data loading failures. Earlier versions had less robust retry mechanisms.
- gotcha Older versions of `aiooui` had a default timeout for fetching OUI data during the build process, which could be too short on slower connections or with large data files, leading to build failures.
Install
-
pip install aiooui
Imports
- OUI
from aiooui import OUI
Quickstart
import asyncio
from aiooui import OUI
async def main():
oui = OUI()
mac_address = '00:08:DC:FF:FF:FF' # Example MAC address (Cisco)
vendor = await oui.lookup(mac_address)
print(f"Vendor for {mac_address}: {vendor}")
# Optionally, look up another known vendor
mac_address_2 = 'F8:F0:05:00:00:00' # Example MAC address (Apple)
vendor_2 = await oui.lookup(mac_address_2)
print(f"Vendor for {mac_address_2}: {vendor_2}")
if __name__ == "__main__":
asyncio.run(main())