Python API Country of Origin for Artists

I’ve been working on development of a python based application that takes advantage of the musicbrainz API. I call get_artist_by_id to look up specific artists and I wanted to also try and include the Country of Origin for the artist if the data is there. I began to notice in my testing that there were quite a few artists that did not return Country of Origin so I investigated. I found that there were quite a few artists that would return more detailed Geographic information (ex: Chicago instead of US) and these cases would not list a country at all. I tried a few of the includes=[] to see if any would provide more data but saw no success. My next step was to take the ID for the area returned and perform a get_area_by_id to see if I could get that to return the country that housed whatever the area may be. I was unsuccessful with that endeavor as well, even toying with the includes=[] for that function. I am wondering if I am missing something for how to get the Country that an area belongs in or to just return the Country when calling information about an artist. I apologize if this question is already answered somewhere and I have missed it.

TL;DR: How to get country of origin and only country (no city/province/state/region/etc.) of an artist using the python api

I don’t think there is a simple way of just requesting the country. You are going to need to get the area id and run sub queries for each level until you find the country.
So if the artist is from Chicago you need to look up the area for chicargo, find the parent and look up that.
ie Find Chicargo, find parent Cook County, find parent Illinois, find parent United States.
Run a query like: https://musicbrainz.org/ws/2/area/29a709d8-0320-493e-8d0c-f2c386662b7f?inc=area-rels&fmt=json
Parse the results and find the “target-type”: “area”, “type”: “part of”, “direction”: “backward” and run the query again with the new id until you have walked up the tree to get area of type “Country”.

2 Likes

Thanks for the response, this is exactly what I was looking for! I didn’t catch the direction field when first looking and only saw the type and everything being “part of”