There is no unified solution for this. Typically what I do in such scenarios is I add a compile-time switch as that is typically how I design the lib at that point. So if the user wants X they need to compile with `nim c -d:enableStdRe <yourfile>`.
In your code you can then put the code inside of a when defined block: when defined (enableStdRe): import std/re <rest your code> Run That way, if the flag is passed, this code is made available. If the flag is not provided, that code will be "cut out" and thus not exist. That would be the most efficient "compile-time" way to do this anyway.