In [ ]:
import pywikibot

site = pywikibot.Site('wikidata', 'wikidata') # for testing use parameter ('test', 'wikidata') to edit
repo = site.data_repository()

# this speeds up the bot run to 1 edit per second (default value: 10 edits per second in PAWS); deactivated to be careful in the beginning
timeToWaitBetweenEdits = 1
site.throttle.setDelays(delay=timeToWaitBetweenEdits, writedelay=timeToWaitBetweenEdits, absolute=True)

# input definition
urlbase = '{}' #für Lübeck
inputdata = { 'Q52767141':'278', 'Q52769051':'111' } # a python dictionary; pairs of Q-ID (dict key) and identifiers (dict value), separated by comma

for inKey, inValue in inputdata.items(): # loop: inKey is the Q-ID from inputdata, inValue the identifier
    Qitem = pywikibot.ItemPage(repo, inKey) # pull item object from Q-ID
    fullUrl = urlbase.format(inValue) # create the actual URL
    urlClaim = pywikibot.Claim(repo, 'P973')
    try: # exception handling required to check whether the item actually exists
        Qitem.addClaim(urlClaim, summary='per request at [[Wikidata:Forum]]') # adds the claim with a custom edit summary
        print('Added to {}: URL "{}"'.format(inKey, fullUrl))
    except (pywikibot.NoPage, pywikibot.OtherPageSaveError):
        print('item {} does not exist; skip'.format(inKey))
print('feddich :-)')
In [ ]: