Why Write a Python Package?¶
A Python package is a grouping of Python modules under a hierarchical namespace.
Packaging code enables it to be indexed, maintained, documented, distributed, and consistently reused:
Prominent open-source Python projects, such as Polars and Pydantic, are distributed as packages.
Packaging practices have standardized over time to facilitate code reuse. While these patterns are vital for large open-source projects, they are equally beneficial in private (inner-source) enterprise environments:
from jambazid.siem import logging
from jambazid.transforms import cleaning
from jambazid.cache.redis import redis_cache
logger: logging.ContextualLogger = logging.get_logger(__name__)
@logging.setup(multiprocessing=True, mode="json")
def main() -> None:
"""
Structured logging, safe and non-blocking - no other setup necessary.
"""
logger.info("event-1", key_1="value-1")
with logging.context(uuid="..."):
logging.info("event-2", key_2="value-2") # inherits `uuid`!
logging.info("event-3", key_3="value-3") # inherits `uuid`!
if __name__ == "__main__":
main()
In the example above, implementing robust logging is non-trivial, but packaging makes it trivial to reuse across multiple services.
Tip
Rather than duplicating code across repositories, developers should include shared functionality as a formal, packaged dependency.
When issues arise, contributors resolve them through a structured development process supported by automated CI/CD pipelines.
Verified changes are published as new, versioned releases. Older versions remain available, mirroring the stability of open-source packages. Maintainers rely on Semantic Versioning (SemVer) to clearly communicate compatibility and breaking changes.