Create Item

import pywikibot
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()

p_official_website = "P856"
p_instance_of = "P31"
q_hackspace = "Q1032372"

#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)

item = pywikibot.ItemPage(repo, "Q4115189")
testhp = "https://www.wikidata.org"

print(type(repo))
#help(pywikibot.Claim)
claim = pywikibot.Claim(repo, p_instance_of)
hackerspaceItem = pywikibot.ItemPage(repo, q_hackspace)
print(hackerspaceItem)
#help(claim)
#print(claim)
claim.setTarget(hackerspaceItem)
item.addClaim(claim)
print(claim)
print(item)

claim = pywikibot.Claim(repo, p_official_website)
claim.setTarget(testhp)
item.addClaim(claim)
print(claim)
<class 'pywikibot.site.DataSite'>
[[wikidata:Q1032372]]
Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P31', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 1032372}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q4115189$5b23b991-7dfb-4113-a160-4c64f34987a7', 'rank': 'normal'})
[[wikidata:Q4115189]]
Sleeping for 9.0 seconds, 2019-05-25 00:37:12
Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P856', 'datatype': 'url', 'datavalue': {'value': 'https://www.wikidata.org', 'type': 'string'}}, 'type': 'statement', 'id': 'Q4115189$e5717b93-d4fa-4c34-8665-e4fe3c2066cb', 'rank': 'normal'})
claim = pywikibot.Claim()
DataSite("test", "wikidata")

Simple Example

import pywikibot

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

new_labels = {"en": "bear", "de": "Bär"}
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"]}
item.editLabels(labels=new_labels, summary="Setting new labels.")
item.editDescriptions(new_descr, summary="Setting new descriptions.")
item.editAliases(new_alias, summary="Setting new aliases.")
Sleeping for 9.6 seconds, 2019-05-24 19:06:10
Sleeping for 9.8 seconds, 2019-05-24 19:06:20

Better Edit Summary

import pywikibot

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

new_labels = {"en": "bear", "de": "Bär"}
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"]}

for key in new_labels:
    item.editLabels(labels={key: new_labels[key]},
        summary="Setting label: {} = '{}'".format(key, new_labels[key]))

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

for key in new_alias:
    item.editAliases({key: new_alias[key]},
        summary="Settings aliases: {} = '{}'".format(key, new_alias[key]))

Alternative: all in one edit

import pywikibot

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

data = {"labels": {"en": "bear", "de": "Bär"},
  "descriptions": {"en": "gentle creature of the forrest", "de": "Friedlicher Waldbewohner"},
       "aliases": {"en": ["brown bear", "grizzly bear", "polar bear"], "de": ["Braunbär", "Grizzlybär", "Eisbär"]},
     "sitelinks": [{"site": "enwiki", "title": "Bear"}, {"site": "dewiki", "title": "Bär"}]}
item.editEntity(data, summary=u'Edited item: set labels, descriptions, aliases')
WARNING: API error no-such-entity: ⧼no-such-entity⧽
---------------------------------------------------------------------------
APIError                                  Traceback (most recent call last)
/srv/paws/pwb/pywikibot/page.py in handle(func, self, *args, **kwargs)
    106         try:
--> 107             func(self, *args, **kwargs)
    108         # TODO: other "expected" error types to catch?

/srv/paws/pwb/pywikibot/page.py in editEntity(self, data, **kwargs)
   4216         updates = self.repo.editEntity(self._defined_by(singular=True), data,
-> 4217                                        baserevid=baserevid, **kwargs)
   4218         self.latest_revision_id = updates['entity']['lastrevid']

/srv/paws/pwb/pywikibot/site.py in callee(self, *args, **kwargs)
   1319                 raise Exception('Not implemented')
-> 1320             return fn(self, *args, **kwargs)
   1321 

/srv/paws/pwb/pywikibot/site.py in editEntity(self, identification, data, bot, **kwargs)
   7838         req = self._simple_request(**params)
-> 7839         data = req.submit()
   7840         return data

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2078 
-> 2079                 raise APIError(**result['error'])
   2080             except TypeError:

APIError: no-such-entity: ⧼no-such-entity⧽ [messages:[{'name': 'no-such-entity', 'parameters': ['Q4115189'], 'html': {'*': '⧼no-such-entity⧽'}}]; help:See https://test.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]

During handling of the above exception, another exception occurred:

OtherPageSaveError                        Traceback (most recent call last)
<ipython-input-2-b23b84b786a3> in <module>
      9        "aliases": {"en": ["brown bear", "grizzly bear", "polar bear"], "de": ["Braunbär", "Grizzlybär", "Eisbär"]},
     10      "sitelinks": [{"site": "enwiki", "title": "Bear"}, {"site": "dewiki", "title": "Bär"}]}
---> 11 item.editEntity(data, summary=u'Edited item: set labels, descriptions, aliases')

/srv/paws/pwb/pywikibot/page.py in wrapper(self, *args, **kwargs)
    126             pywikibot.async_request(handle, func, self, *args, **kwargs)
    127         else:
--> 128             handle(func, self, *args, **kwargs)
    129 
    130     manage_wrapping(wrapper, func)

/srv/paws/pwb/pywikibot/page.py in handle(func, self, *args, **kwargs)
    118                 if isinstance(err, pywikibot.PageSaveRelatedError):
    119                     raise err
--> 120                 raise pywikibot.OtherPageSaveError(self, err)
    121         if callback:
    122             callback(self, err)

OtherPageSaveError: Edit to page [[wikidata:test:Q4115189]] failed:
no-such-entity: ⧼no-such-entity⧽ [messages:[{'name': 'no-such-entity', 'parameters': ['Q4115189'], 'html': {'*': '⧼no-such-entity⧽'}}]; help:See https://test.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]