2. Use your experience as a library user to write code using the library.
3. Implement the library so that the code from step 2 actually works.
If you discover that your implementation seems to require a lot of boilerplate and you suspect that metaprogramming could help simplify things, you can try it. Otherwise don't bother.
If you can do that, making it into a proper module that you can pip install is just a matter of adding a pyproject.toml, adding an __init__.py, moving your functions into a new file and a few thing like that.
Generally you should not have any shared variables that are internal to the module (if that's what you're imagining.) If you don't know how to use advanced python constructs ypu don't need them.