You can write your own function in Python easily enough using one of the many excellent Python APIs available. Have a look at GDAL/OGRGDAL/OGR. The documentation is focussed on C++ but you should be able to understand it enough to figure out the Pythonic equivalent. A great tutorial on this can be found herehere. Alternatively try 'ShapelyShapely'. If you are comfortable with databases have a look at PostGISPostGIS or SpatiaLiteSpatiaLite.
All of these have Python API that will allow you to construct your own queries for all the spatial queries that you can find in QGIS or ArcGIS or almost any GIS. To get started I recommend going through the tutorial for GDAL/OGR above and then branching out.