How to locally quantify the 'sharpness' of an image?
The recent works I am aware of make use of tools that go beyond mere gradients. Here are a few references that could be starting points:


S3: A Spectral and Spatial Measure of Local Perceived Sharpness in Natural Images, 2012, with examples of sharpness maps and Matlab code (that could  be converted to Python)



  This paper presents an algorithm designed to measure the local perceived sharpness in an image. Our method utilizes both spectral and spatial properties
  of the image: For each block, we measure the slope of the magnitude
  spectrum and the total spatial variation. These measures are then
  adjusted to account for visual perception, and then, the adjusted
  measures are combined via a weighted geometric mean. The resulting
  measure, i.e., S3 (spectral and spatial sharpness), yields a perceived
  sharpness map in which greater values denote perceptually sharper
  regions



Image sharpness assessment based on local phase coherence, 2013, with examples  and (BROKEN yet) code (local copy of the code provided by the authors)



  Sharpness is an important determinant in visual assessment of image
  quality. The human visual system is able to effortlessly detect blur
  and evaluate sharpness of visual images, but the underlying mechanism
  is not fully understood. Existing blur/sharpness evaluation algorithms
  are mostly based on edge width, local gradient, or energy reduction of
  global/local high frequency content. Here we understand the subject
  from a different perspective, where sharpness is identified as strong
  local phase coherence (LPC) near distinctive image features evaluated
  in the complex wavelet transform domain. Previous LPC computation is
  restricted to be applied to complex coefficients spread in three
  consecutive dyadic scales in the scale-space. Here we propose a
  flexible framework that allows for LPC computation in arbitrary
  fractional scales.


The given examples and comparisons across different  could provide you with  some hints toward your goal.