How to obtain a .png image (inside a fixed bounding box) from OpenStre

What I need is to obtain an image in .png format like the one obtained from OpenStreetMap if you select the bounding box and then you click on the Share buttom and download the image. But I need is to do that in Python, to be able to change the bounding box values and each time I don’t have to go to this web and download the image manually.

Here is a screen capture of how to do this in Open Street Map’s web, manually, with a fixed bounding box (you can see the values in the upper left corner). You go to Share, and then Download the image setting the image type to png.

I would really appreciate any help about how to do this in Python. Thanks in advance.

If you just want to automate the process, but are ok with actual work happening on remote servers, you can check out the API I provide on my MapOSMatic instance:

If you want to render locally you need to set up python-mapnik, the OpenStreetMap CartoCSS style (preprocessed for Mapnik), various shapefiles, and an OpenStreetMap database extract for the region you want to cover, imported into a PostGIS database using the osm2pgsql tool.

The actual Python rendering code then is pretty simple, the tricky part is to set up all the infrastructure. See e.g.

You could try to set up the vagrant/virtualbox environment I use for testing, with a data extract of your choice. That would give you a working local MapOSMatic setup, including the API, and you could also write your own Python rendering tools in that environment, as that already has the full infrastructure set up once the VM has successfully finished running the included provisioning scripts.

Or you could create your own setup and just use the various scripts in the inc/ subdirectory as a sort of how-to …