Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

example python package performing addition

Project description

# Overview

This repo is for creating best practice python packages. Marco Bonzanini’s [definition](https://marcobonzanini.com/2015/07/01/how-to-develop-and-distribute-python-packages/) of a package is as follows:

> In Python, a simple source file containing the definitions of functions, classes and variables, is a module… On the other side, a package is a folder containing an __init__.py file, as well as other different Python source files. Typically a package contains several modules and sub-packages.

This repo assumes you have understanding how to set up a Python Module and have done so before going any further.

# Unit Testing

For unit testing, Dive Into Python 3’s example of [unit testing](http://www.diveintopython3.net/unit-testing.html) is a great resource. It’s a simple Roman Numeral conversion example that walks you through the bulk of what you’ll need to know.

# Logging

Should an error occur when the package is live, logs are a great method to provide information to stdout. Jorgen Schaefer’s [guide to logging](https://www.loggly.com/ultimate-guide/python-logging-basics/) establishes logging convention, and the developer’s role.

As logging doens’t function part of the example ‘maths’ module, I’m currently of the opinion that it can be kept in a seperate utils module

# Error Handling

Naturally this moves us on to custom error handling where Aaron Maxwell’s [exceptional logging of exceptions](https://www.loggly.com/blog/exceptional-logging-of-exceptions-in-python/) article takes centre stage. It’s a moderate advancement on the error handling you were used to in the unit testing example, but does allow us to capture and relay traceback information in defined patterns.

It additionally defines anti-patterns for which neither the Unit Testing or Loggging links provide, i.e. what is considered unacceptable logging.

### Notes

  • This tutorial assumes you know about Python classes. If not, look no further than Python’s [classes tutorial](https://docs.python.org/3/tutorial/classes.html)
  • ‘exc_info’ returns ‘NoneType: None’ should ‘if else raise’ statements be performed.

# Creating a Package

Project details


Release history Release notifications

This version
History Node

0.1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
example_maths-0.1.1-py3-none-any.whl (7.6 kB) Copy SHA256 hash SHA256 Wheel 3.6

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page