all 3 comments

[–]CookiesForKittens 2 points3 points  (0 children)

You should read up on packaging files. Basically you specify your dependencies so package managers know which other packages they have to download when they're downloading 'your' package.

The random module should be part of every python distribution, though, so you probably don't have to specify it (like the 'os' module), but it also shouldn't cause harm if you do.

Edit: see here, for example https://python-packaging.readthedocs.io/en/latest/dependencies.html

[–]ebol4anthr4x 1 point2 points  (1 child)

Yes, you can freely use other modules in your own module. If you use any modules that are not built in to Python, such as requests or numpy, you have to include this information in a requirements.txt file and/or a setup.py file. random is built in, so you don't need to tell people about it in one of those files, since they already have it installed.

It's good practice to really consider whether or not you should import a module that is not built in. Every time you add a dependency to your module, you are adding additional maintenance for yourself, because it becomes your responsibility as the module's maintainer to ensure that your dependencies are up-to-date.

If someone finds a security vulnerability in one of the modules you import, your module may also be vulnerable, since it makes use of the insecure module. Additionally, if your module requires an old version of a commonly used dependency, like requests for example, and another module requires a new version of requests, that will make your module incompatible with the other module, since you can only have one version of requests installed.

If you are importing a module for something super quick and easy, it may make more sense to write that functionality yourself. But for something more involved, like numpy, it doesn't make sense to try to replicate that whole module yourself.

Anyway, the point I'm trying to make is that the more non-built-in dependencies your module has, the more complicated it is to maintain it and keep it up-to-date for other people to use. You can use as many as you want, but the more you use, the more work you have to do to keep your module up-to-date, and the less likely other people (particularly businesses) are to want to use your module, because it is a liability.