If I follow you correctly then this one may answer part of your question (though without code):
depending on what your project requires geostan may offer something for you