How to convert BAM file to bigWig in Python?
deepTools has a (somewhat poorly documented) API, since it's a python package too. The basic code framework is:

from deeptools import writeBedGraph
from deeptools.getScaleFactor import get_scale_factor

wr = writeBedGraph.WriteBedGraph(options and input files)
func_args = {'scaleFactor': get_scale_factor(...options...)}
wr.run(writeBedGraph.scaleCoverage, func_args, output_file_name, ...)