Python API: combining searches

I’m using Python to make my queries to the MusicBrainz API (using musicbrainzngs), I need my query to return a random recording between certain years by a random artist that is from a specific country.

I’ve been able to get a random artist using:
musicbrainzngs.search_artists(area="france", limit=1, offset=0
I can offset to be a random number between 0 and the number of artists found in the query

Within this I can loop through the artists’ recordings and pick one at random, and I can specify it to randomly pick a recording that was recorded in a specific year.

This all works fine, but I wanted to find out if it was possible to combine all of this, or more of it, into a single query, so I didn’t have to loop through as much data. As it is right now I have to download all of the data about an artist, loop through all of their recordings and find one from a certain year, it might be that the random artist never released recordings in the year I need so then it would need to pick another artist. This is quite inefficient as you can imagine!

AFAIK, there’s no such built-in MB api to do this.

However, @rob wrote an experimental endpoint Dataset hoster: area-random-recordings that does exactly what you want. The caveat is that its “experimental” and may change in future without notice.

If you are interested in using this, I suggest you to come in #metabrainz IRC and discuss it with the devs.

Are you able to describe what query he’s using to perform that search? I’ve read through the relationships part of the docs and it’s not making a huge amount of sense :sweat_smile: