The most common way to do this is to use or require the optional module in an eval string, then see whether that succeeded to decide whether to use the feature or not. The advantage to doing it at runtime is that if a user later installs the optional module, your code will just start using it.