# Python API Country of Origin for Artists

**URL:** <https://community.metabrainz.org/t/python-api-country-of-origin-for-artists/491476>\
**Category:** Development\
**Tags:** artist, python, musicbrainz\
**Created:** [August 22, 2020, 1:39pm UTC](https://community.metabrainz.org/t/python-api-country-of-origin-for-artists/491476 "2020-08-22T13:39:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IAmTheBlackMetal](https://community.metabrainz.org/user_avatar/community.metabrainz.org/iamtheblackmetal/32/58790_2.png) [@IAmTheBlackMetal](https://community.metabrainz.org/u/IAmTheBlackMetal)\
**Post date:** [August 22, 2020, 1:39pm UTC](https://community.metabrainz.org/t/python-api-country-of-origin-for-artists/491476/1 "2020-08-22T13:39:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dns\_server](https://community.metabrainz.org/user_avatar/community.metabrainz.org/dns_server/32/175_2.png) [@dns\_server](https://community.metabrainz.org/u/dns_server)\
**Post date:** [August 26, 2020, 3:19am UTC](https://community.metabrainz.org/t/python-api-country-of-origin-for-artists/491476/2 "2020-08-26T03:19:05Z")

</div>

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](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”.

---

<div class="post-metadata">

**Author:** ![IAmTheBlackMetal](https://community.metabrainz.org/user_avatar/community.metabrainz.org/iamtheblackmetal/32/58790_2.png) [@IAmTheBlackMetal](https://community.metabrainz.org/u/IAmTheBlackMetal)\
**Post date:** [August 30, 2020, 9:01pm UTC](https://community.metabrainz.org/t/python-api-country-of-origin-for-artists/491476/3 "2020-08-30T21:01:18Z")

</div>

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”
