How Can I Hide Imported Libraries in My Python Module?

0
6
Asked By CreativeCoder99 On

Hey everyone! I'm developing a Python package, and I've noticed that when I import libraries at the start of one of my modules, they become accessible from outside my package. For instance, I'm importing 'os', 'numpy', and 'Any' from 'typing'. This means someone can do something like 'from mypackage.mymodule import os, np, Any', which isn't ideal for me. Is there a way to hide these imports? I know it might sound silly, but I'm really looking for a solution! I found some partial fixes, but none actually seem to completely obscure the imports, even in Visual Studio Code. I've heard Python isn't built for code privacy, but I'm curious if anyone has advice on how to manage this better, maybe like how Astropy handles their imports by wrapping dependencies.

1 Answer

Answered By PythonNinja42 On

Honestly, I don't think you can completely hide the imports, but I'm curious why this is an issue for you. Could you share a bit more?

CreativeCoder99 -

It’s not such a big deal, really! I just want my package to look clean and make it easy for others, especially newcomers, to understand without too much confusion. I know some packages handle their dependencies in a slick way, so I thought there had to be a method!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.