import pywikibot
site = pywikibot.Site("test", "wikidata")

def create_item(site, label_dict):
    new_item = pywikibot.ItemPage(site)
    new_item.editLabels(labels=label_dict, summary="Setting labels")
    # Add description here or in another function
    return new_item.getID()

some_labels = {"en": "Hamburg Main Station", "de": "Hamburg Hauptbahnhof"}
new_item_id = create_item(site, some_labels)

print(new_item_id)
Q94925
import pywikibot

site = pywikibot.Site("test", "wikidata")
repo = site.data_repository()
item = pywikibot.ItemPage(repo, "Q94923")

new_labels = {"en": "bear", "de": "Bär", "yue": "熊"}
new_descr = {"en": "gentle creature of the forrest_", "de": "Friedlicher Waldbewohner_"}
new_alias = {"en": ["brown bear", "grizzly bear", "polar bear"], "de": ["Braunbär", "Grizzlybär", "Eisbär"]}
print('Edits set up')

item.editLabels(labels=new_labels, summary="Setting new labels.")
print('Labels done')

item.editDescriptions(new_descr, summary="Setting new descriptions.")
print('Descriptions done')

item.editAliases(new_alias, summary="Setting new aliases.")
print('Aliases done')

print(item.get()["labels"])
Edits set up
Labels done
Sleeping for 9.7 seconds, 2017-11-02 01:22:43
Descriptions done
Sleeping for 9.8 seconds, 2017-11-02 01:22:52
Aliases done
{'en': 'bear', 'de': 'Bär', 'yue': '熊'}

Pitfall: If any line encounters an error from Wikidata, the rest of the script is suspended

This happened when running the script multiple times, which caused the server to throw the error that an item with the same label and description has already been created.

pywikibot also sleeps for 10s between editing operations to throttle itself.

print(dir(item))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', '_cache_attrs', '_cmpkey', '_content', '_cosmetic_changes_hook', '_defined_by', '_diff_to', '_getInternals', '_get_parsed_page', '_isredir', '_latest_cached_revision', '_link', '_namespace', '_namespace_obj', '_normalizeData', '_normalizeLanguages', '_revid', '_revisions', '_save', 'addClaim', 'aliases', 'applicable_protections', 'aslink', 'autoFormat', 'backlinks', 'botMayEdit', 'canBeEdited', 'categories', 'change_category', 'claims', 'clear_cache', 'concept_uri', 'concept_url', 'content_model', 'contributingUsers', 'contributors', 'coordinates', 'data_item', 'data_repository', 'defaultsort', 'delete', 'depth', 'descriptions', 'editAliases', 'editDescriptions', 'editEntity', 'editLabels', 'editTime', 'embeddedin', 'encoding', 'entity_type', 'exists', 'expand_text', 'extlinks', 'fromPage', 'from_entity_uri', 'fullVersionHistory', 'full_url', 'get', 'getCategoryRedirectTarget', 'getCreator', 'getDeletedRevision', 'getID', 'getLatestEditors', 'getMovedTarget', 'getOldVersion', 'getRedirectTarget', 'getReferences', 'getRestrictions', 'getSitelink', 'getTemplates', 'getVersionHistory', 'getVersionHistoryTable', 'getdbName', 'id', 'image_repository', 'imagelinks', 'interwiki', 'isAutoTitle', 'isCategory', 'isCategoryRedirect', 'isDisambig', 'isEmpty', 'isFlowPage', 'isImage', 'isIpEdit', 'isRedirectPage', 'isStaticRedirect', 'isTalkPage', 'is_categorypage', 'is_filepage', 'is_flow_page', 'is_valid_id', 'iterlanglinks', 'iterlinks', 'itertemplates', 'labels', 'langlinks', 'lastNonBotUser', 'latestRevision', 'latest_revision', 'latest_revision_id', 'linkedPages', 'loadDeletedRevisions', 'markDeletedRevision', 'mergeInto', 'merge_history', 'move', 'moved_target', 'namespace', 'oldest_revision', 'pageAPInfo', 'page_image', 'pageid', 'permalink', 'preloadText', 'previousRevision', 'previous_revision_id', 'properties', 'protect', 'protection', 'purge', 'put', 'put_async', 'removeClaims', 'removeImage', 'removeSitelink', 'removeSitelinks', 'replaceImage', 'repo', 'revision_count', 'revisions', 'save', 'section', 'sectionFreeTitle', 'setSitelink', 'setSitelinks', 'set_redirect_target', 'site', 'sitelinks', 'templates', 'text', 'title', 'titleForFilename', 'titleWithoutNamespace', 'title_pattern', 'toJSON', 'toggleTalkPage', 'touch', 'undelete', 'urlname', 'userName', 'version', 'watch']
print(item.getID())
type(item.getID())
Q94923
str
import pywikibot

site = pywikibot.Site("test", "wikidata")
repo = site.data_repository()
item = pywikibot.ItemPage(repo, new_item_id)

new_labels = {"en": "bear", "de": "Bär"}
new_descr = {"en": "weird creature of the forrest 2",
             "de": "Unbewöhner Waldbewohner 2"}
new_alias = {"en": ["brown bear", "grizzly bear", "polar bear"],
             "de": ["Braunbär", "Grizzlybär", "Eisbär"]}

editcount = 0

for key in new_labels:
    item.editLabels(labels={key: new_labels[key]},
        summary="Setting label: {} = '{}'".format(key, new_labels[key]))
    editcount = editcount + 1 #Deryck added these to tell himself where the script is going
    print(editcount)

for key in new_descr:
    item.editDescriptions({key: new_descr[key]},
        summary="Setting description: {} = '{}'".format(key, new_descr[key]))
    editcount = editcount + 1
    print(editcount)

for key in new_alias:
    item.editAliases({key: new_alias[key]},
        summary="Settings aliases: {} = '{}'".format(key, new_alias[key]))
    editcount = editcount + 1
    print(editcount)
    
print("finish")
1
Sleeping for 9.8 seconds, 2017-11-02 01:36:43
2
Sleeping for 9.8 seconds, 2017-11-02 01:36:53
3
Sleeping for 9.7 seconds, 2017-11-02 01:37:03
4
Sleeping for 9.8 seconds, 2017-11-02 01:37:13
5
Sleeping for 9.8 seconds, 2017-11-02 01:37:23
6
finish

It's one edit per language per type of stuff (label, description, alias)!