Building a package

So far in this book, we have been either using third-party packages, such as requests and pandas, or writing raw code as .py scripts or notebooks. While using Python files directly is absolutely fine for certain projects, it makes it hard for code to be reused and built upon; it is not sustainable for complex algorithms and tools that can be used over and over again. Such code is also hard to share as it has no overall structure, tends to decay over time, and doesn't have a robust dependency system; the code may not work on other systems with other packages (or other versions of packages) installed. Last but not least, this kind of practice affects the quality of our code, as we tend to write and use the code as a one-time solution. The best way to mitigate all those issues at once is to form your code into a package.

But what is a package? In Python, packages are defined as specific bodies of code that are registered in the system (via a system path) and thus can be imported and used in any specific code base. Packages are stored on the dedicated system paths and are not meant to be changed or deployed manually. Instead, it is preferable to use dedicated tools, such as the built-in setuptool package or package managers (for example, pip or conda). We'll learn about these in detail in the coming sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.92.215