import pywikibot

SITE = pywikibot.Site("wikidata", "wikidata")
REPO = SITE.data_repository()

JIMI = 'Q4115189'
LAST_FM_ID = 'P973'
VALUE = 'https://digilander.libero.it/John.Legend/'

STATED_IN_REFERENCE = pywikibot.Claim(REPO, 'P248', is_reference=True)

subject = pywikibot.ItemPage(REPO, JIMI)
claim = pywikibot.Claim(REPO, LAST_FM_ID)

existing_claims = subject.get()['claims']
values = existing_claims.get(LAST_FM_ID)
for value in values:
    if value.getTarget() == VALUE:
        STATED_IN_REFERENCE.setTarget(pywikibot.ItemPage(REPO, 'Q666'))
        value.addSources([STATED_IN_REFERENCE])