Sometimes importing/depending on a library is exactly what's needed.
Sometimes importing/depending on a library means you're permanently saddled with an unmaintained, inflexible, third-party white elephant.
These outcomes are not mutually exclusive. One of my apps even has a directory called "lib/boondoggles/" because it includes so many of these. It works fine, but I will never revise it.
- Implement it in pseudocode
- Write the simplest code that will work end-to-end, and work outwards from there
- Find a library that does it