import pywikibot
site = pywikibot.Site('test', 'wikipedia')
site
APISite("test", "wikipedia")
page = pywikibot.Page(site, 'test')
page.exists()
True
page.text
'Hello world!'
page.text = 'Hello world'
page.save()
Page [[Test]] saved
https://test.wikipedia.org/wiki/User_talk:<username>import pywikibot

site = pywikibot.Site('test', 'wikipedia')
page = pywikibot.Page(site, 'test')

page.text = 'Hello world!'
page.save()
Page [[Test]] saved
help(page.save)
Help on method save in module pywikibot.page:

save(...) method of pywikibot.page.Page instance
    Save the current contents of page's text to the wiki.
    
    @param summary: The edit summary for the modification (optional, but
        most wikis strongly encourage its use)
    @type summary: unicode
    @param watch: Specify how the watchlist is affected by this edit, set
        to one of "watch", "unwatch", "preferences", "nochange":
        * watch: add the page to the watchlist
        * unwatch: remove the page from the watchlist
        * preferences: use the preference settings (Default)
        * nochange: don't change the watchlist
        If None (default), follow bot account's default settings
    
        For backward compatibility watch parameter may also be boolean:
        if True, add or if False, remove this Page to/from bot
        user's watchlist.
    @type watch: string, bool (deprecated) or None
    @param minor: if True, mark this edit as minor
    @type minor: bool
    @param botflag: if True, mark this edit as made by a bot (default:
        True if user has bot status, False if not)
    @param force: if True, ignore botMayEdit() setting
    @type force: bool
    @param asynchronous: if True, launch a separate thread to save
        asynchronously
    @param callback: a callable object that will be called after the
        page put operation. This object must take two arguments: (1) a
        Page object, and (2) an exception instance, which will be None
        if the page was saved successfully. The callback is intended for
        use by bots that need to keep track of which saves were
        successful.
    @param apply_cosmetic_changes: Overwrites the cosmetic_changes
        configuration value to this value unless it's None.
    @type apply_cosmetic_changes: bool or None
    @param quiet: enable/disable successful save operation message;
        defaults to False.
        In asynchronous mode, if True, it is up to the calling bot to
        manage the output e.g. via callback.
    @type quiet: bool

import pywikibot

site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)

print(item)
[[wikidata:Q42]]
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', '_normalizeData', '_normalizeLanguages', '_pageid', '_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', 'removeSitelink', 'removeSitelinks', '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.exists())
True
item_dict = item.get()
print(item_dict.keys())
dict_keys(['aliases', 'labels', 'descriptions', 'claims', 'sitelinks'])
print(item_dict["labels"])
{'fr': 'Douglas Adams', 'ru': 'Дуглас Адамс', 'pl': 'Douglas Adams', 'it': 'Douglas Adams', 'en-gb': 'Douglas Adams', 'nb': 'Douglas Adams', 'es': 'Douglas Adams', 'en-ca': 'Douglas Adams', 'hr': 'Douglas Adams', 'pt': 'Douglas Adams', 'ko': '더글러스 애덤스', 'nl': 'Douglas Adams', 'el': 'Ντάγκλας Άνταμς', 'ar': 'دوغلاس آدمز', 'arz': 'دوجلاس ادامز', 'bar': 'Douglas Adams', 'be': 'Дуглас Адамс', 'bg': 'Дъглас Адамс', 'bs': 'Douglas Adams', 'ca': 'Douglas Adams', 'cs': 'Douglas Adams', 'cy': 'Douglas Adams', 'da': 'Douglas Adams', 'eo': 'Douglas Adams', 'et': 'Douglas Adams', 'fa': 'داگلاس آدامز', 'fi': 'Douglas Adams', 'ga': 'Douglas Adams', 'gl': 'Douglas Adams', 'he': 'דאגלס אדמס', 'hu': 'Douglas Adams', 'id': 'Douglas Adams', 'io': 'Douglas Adams', 'is': 'Douglas Adams', 'ja': 'ダグラス・アダムズ', 'jv': 'Douglas Adams', 'ka': 'დაგლას ადამსი', 'la': 'Duglassius Adams', 'lv': 'Duglass Adamss', 'mk': 'Даглас Адамс', 'mr': 'डग्लस अॅडम्स', 'nn': 'Douglas Adams', 'ro': 'Douglas Adams', 'sco': 'Douglas Adams', 'sh': 'Douglas Adams', 'sk': 'Douglas Adams', 'sl': 'Douglas Adams', 'sq': 'Douglas Adams', 'sr': 'Даглас Адамс', 'sv': 'Douglas Adams', 'ta': 'டக்ளஸ் ஆடம்ஸ்', 'tr': 'Douglas Adams', 'uk': 'Дуглас Адамс', 'vi': 'Douglas Adams', 'zh': '道格拉斯·亚当斯', 'zh-cn': '道格拉斯·亚当斯', 'zh-hans': '道格拉斯·亚当斯', 'zh-hant': '道格拉斯·亞當斯', 'de-ch': 'Douglas Adams', 'pt-br': 'Douglas Adams', 'zh-sg': '道格拉斯·亚当斯', 'zh-my': '道格拉斯·亚当斯', 'zh-hk': '道格拉斯·亞當斯', 'zh-tw': '道格拉斯·亞當斯', 'zh-mo': '道格拉斯·亞當斯', 'war': 'Douglas Adams', 'be-tarask': 'Дуглас Адамз', 'vep': 'Adams Duglas', 'ur': 'ڈگلس ایڈم', 'oc': 'Douglas Adams', 'af': 'Douglas Adams', 'an': 'Douglas Adams', 'br': 'Douglas Adams', 'eu': 'Douglas Adams', 'lb': 'Douglas Adams', 'lmo': 'Douglas Adams', 'lt': 'Douglas Adams', 'nds': 'Douglas Adams', 'nds-nl': 'Douglas Adams', 'pms': 'Douglas Adams', 'vec': 'Douglas Adams', 'wa': 'Douglas Adams', 'sr-ec': 'Даглас Адамс', 'sr-el': 'Daglas Adams', 'de': 'Douglas Adams', 'ckb': 'دەگلاس ئادمز', 'fo': 'Douglas Adams', 'kl': 'Douglas Adams', 'gsw': 'Douglas Adams', 'te': 'డగ్లస్ ఆడమ్స్', 'si': 'ඩග්ලස් ඇඩම්ස්', 'bn': 'ডগলাস অ্যাডামস', 'hi': 'डग्लस अ\u200dडम्स', 'rwr': 'डग्लस अ\u200dडम्स', 'mg': 'Douglas Adams', 'ml': 'ഡഗ്ലസ് ആഡംസ്', 'gu': 'ડગ્લાસ એડમ્સ', 'hy': 'Դուգլաս Ադամս', 'ast': 'Douglas Adams', 'co': 'Douglas Adams', 'de-at': 'Douglas Adams', 'frp': 'Douglas Adams', 'fur': 'Douglas Adams', 'gd': 'Douglas Adams', 'ia': 'Douglas Adams', 'ie': 'Douglas Adams', 'kg': 'Douglas Adams', 'li': 'Douglas Adams', 'lij': 'Douglas Adams', 'min': 'Douglas Adams', 'ms': 'Douglas Adams', 'nap': 'Douglas Adams', 'nrm': 'Douglas Adams', 'pcd': 'Douglas Adams', 'rm': 'Douglas Adams', 'sc': 'Douglas Adams', 'scn': 'Douglas Adams', 'sw': 'Douglas Adams', 'vls': 'Douglas Adams', 'vo': 'Douglas Adams', 'wo': 'Douglas Adams', 'zu': 'Douglas Adams', 'az': 'Duqlas Noel Adams', 'ak': 'Doglas Adams', 'or': 'ଡଗ୍\u200cଲାସ୍\u200c ଆଦାମ୍\u200cସ', 'kn': 'ಡಗ್ಲಸ್ ಆಡಮ್ಸ್', 'ne': 'डगलस एडम्स', 'mrj': 'Адамс', 'th': 'ดั๊กลาส อดัมส์', 'pa': 'ਡਗਲਸ ਐਡਮਜ਼', 'tcy': 'ಡಾಗ್ಲಸ್ ಆಡಮ್ಸ್', 'tl': 'Douglas Adams', 'ext': 'Douglas Adams', 'azb': 'داقلاس آدامز', 'en': 'Douglas Adams', 'lfn': 'Douglas Adams', 'nan': 'Douglas Adams', 'ky': 'Дуглас Адамс'}
import pywikibot

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

#Get the item
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
item = pywikibot.ItemPage(repo, "Q2225")

item_dict = item.get() #Get the item dictionary
clm_dict = item_dict["claims"] # Get the claim dictionary
print(clm_dict)
{'P1360': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1360', 'datatype': 'string', 'datavalue': {'value': '11', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$56c49ee0-4c6b-4804-bc6b-a26fc4b26dbf', 'rank': 'normal', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 17323608}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': '379bff50d1450626291cc3ffe4a477aa69b9d7dc'}]})], 'P279': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P279', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 82586}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'q2225$CA3B52EE-5E76-4A3D-B2CB-0DDDC21E7B0B', 'rank': 'normal'})], 'P1036': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1036', 'datatype': 'string', 'datavalue': {'value': '539.72112', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$908ade56-4ff1-95b3-1521-eb8d4249c2b0', 'rank': 'normal'})], 'P373': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P373', 'datatype': 'string', 'datavalue': {'value': 'Electrons', 'type': 'string'}}, 'type': 'statement', 'id': 'q2225$1C523D9A-862E-4DC0-8D99-FEAA60D872A1', 'rank': 'normal'})], 'P227': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P227', 'datatype': 'external-id', 'datavalue': {'value': '4125978-6', 'type': 'string'}}, 'type': 'statement', 'id': 'q2225$A910F863-6788-4281-A073-1973C5083665', 'rank': 'normal', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 48183}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': '9a24f7c0208b05d6be97077d855671d1dfdbc0dd'}]})], 'P517': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P517', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 11418}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$77575a0c-4a43-2b4d-cef4-8a17ffd7db68', 'rank': 'normal'}), Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P517', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 849919}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$a571422c-4a60-65ed-3642-7c8675766bfd', 'rank': 'normal'}), Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P517', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 11412}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$0f7a27de-4db4-2f88-b04f-5c383b035cb0', 'rank': 'normal'})], 'P508': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P508', 'datatype': 'external-id', 'datavalue': {'value': '3791', 'type': 'string'}}, 'type': 'statement', 'id': 'q2225$48F396B9-5515-4CCE-95E8-DE75AA8DDB77', 'rank': 'normal', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 460907}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': 'b7232a03e568ea326dacdccb6322adb7894300d5'}]})], 'P910': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P910', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 8411332}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$334BBD54-F057-4FB1-A279-507370DCA326', 'rank': 'normal', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 14380}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': '60cf770260aef7fc2fed6c981da268725c641b94'}]})], 'P349': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P349', 'datatype': 'external-id', 'datavalue': {'value': '00561425', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$F288E882-7E99-445F-BF7F-A4EC89FDC7FE', 'rank': 'normal'})], 'P1122': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1122', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '+0.5', 'upperBound': None, 'lowerBound': None, 'unit': '1'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$9760e517-4f85-d808-50e7-85698fe554bf', 'rank': 'normal'})], 'P1123': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1123', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '+1', 'upperBound': None, 'lowerBound': None, 'unit': '1'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$88d2984d-46ce-c948-02a9-55d93079d0c3', 'rank': 'normal'})], 'P646': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P646', 'datatype': 'external-id', 'datavalue': {'value': '/m/02l7x', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$C4FACE8D-F599-4C69-8623-80C7FE64402B', 'rank': 'normal', 'references': [{'snaks': {'P248': [{'snaktype': 'value', 'property': 'P248', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 15241312}, 'type': 'wikibase-entityid'}}], 'P577': [{'snaktype': 'value', 'property': 'P577', 'datatype': 'time', 'datavalue': {'value': {'time': '+00000002013-10-28T00:00:00Z', 'precision': 11, 'after': 0, 'before': 0, 'timezone': 0, 'calendarmodel': 'http://www.wikidata.org/entity/Q1985727'}, 'type': 'time'}}]}, 'snaks-order': ['P248', 'P577'], 'hash': '2b00cb481cddcac7623114367489b5c194901c4a'}]})], 'P1014': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1014', 'datatype': 'external-id', 'datavalue': {'value': '300264243', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$49D14258-FE09-458A-9831-2A9F8CC3397A', 'rank': 'normal'})], 'P1051': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1051', 'datatype': 'external-id', 'datavalue': {'value': '3701', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$08AD62CB-C11D-42D8-90D6-76D3EFE7A401', 'rank': 'normal'})], 'P61': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P61', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 47285}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$cf471463-4476-9ee7-25b1-6328e2307db9', 'rank': 'normal'})], 'P575': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P575', 'datatype': 'time', 'datavalue': {'value': {'time': '+00000001897-00-00T00:00:00Z', 'precision': 9, 'after': 0, 'before': 0, 'timezone': 0, 'calendarmodel': 'http://www.wikidata.org/entity/Q1985727'}, 'type': 'time'}}, 'type': 'statement', 'id': 'Q2225$9e03b33c-4b89-ebc7-a07f-f8dba057abf6', 'rank': 'normal'})], 'P31': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P31', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 22675015}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$C62338D6-971A-4FBB-8CA8-2CAC19C43913', 'rank': 'normal'})], 'P2069': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2069', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '-1.00115965218076', 'upperBound': '-1.00115965218075', 'lowerBound': '-1.00115965218077', 'unit': 'http://www.wikidata.org/entity/Q737120'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$edaaaf4e-48fd-6503-016c-27d857e55f40', 'rank': 'normal'})], 'P2152': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2152', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 3229}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$c0d4e2e5-4517-6968-d118-854f1b78c23d', 'rank': 'normal'})], 'P2200': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2200', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '-1', 'upperBound': None, 'lowerBound': None, 'unit': 'http://www.wikidata.org/entity/Q2101'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$f6f6e26b-4f3e-fb2b-e1d1-64734af0e45c', 'rank': 'normal'})], 'P2375': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2375', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 1087203}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$ab40a257-41ab-d688-709f-abdacb2a1e65', 'rank': 'normal', 'qualifiers': {'P31': [{'snaktype': 'value', 'property': 'P31', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 41719}, 'type': 'wikibase-entityid'}, 'hash': 'da9e8ccbb9a2d14e3b0495df4a459dc9386e4e2f'}]}, 'qualifiers-order': ['P31']})], 'P18': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P18', 'datatype': 'commonsMedia', 'datavalue': {'value': 'Single electron probability pattern.png', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$3479e9d8-4902-0c01-e351-f42323b3b6a6', 'rank': 'normal'})], 'P3417': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P3417', 'datatype': 'external-id', 'datavalue': {'value': 'Electrons', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$35DF88B3-F55E-4593-9117-DC762BD156A6', 'rank': 'normal', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 51711}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': 'd0b5b6346d38f7e212f576fec2c6692ef2b86e6a'}]})], 'P3827': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P3827', 'datatype': 'external-id', 'datavalue': {'value': 'electrons', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$9269A7D8-741E-4B65-B5F8-97037E9BEEF9', 'rank': 'normal'})], 'P3916': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P3916', 'datatype': 'external-id', 'datavalue': {'value': 'concept9543', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$B40DD64D-95C4-4F8B-A929-2AE94FC49A41', 'rank': 'normal'})], 'P2067': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2067', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '+0.00054857990907016', 'upperBound': None, 'lowerBound': None, 'unit': 'http://www.wikidata.org/entity/Q483261'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$45e73d74-44f3-b546-1faa-b1a59d75e7f7', 'rank': 'normal', 'references': [{'snaks': {'P854': [{'snaktype': 'value', 'property': 'P854', 'datatype': 'url', 'datavalue': {'value': 'http://physics.nist.gov/cgi-bin/cuu/Value?me', 'type': 'string'}}]}, 'snaks-order': ['P854'], 'hash': 'd2e3e5a11a866698e0bbce4b25b7d3e3f651ab64'}]})], 'P138': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P138', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 25381}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$98fefef9-4f12-2a5f-c60a-457cc450a062', 'rank': 'normal'})], 'P683': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P683', 'datatype': 'external-id', 'datavalue': {'value': '10545', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$8d21ddeb-4bad-0e9a-02b1-bf36285c50c0', 'rank': 'normal'})], 'P486': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P486', 'datatype': 'external-id', 'datavalue': {'value': 'D004583', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$1841CA3D-103A-4A02-B6F7-AB0CDF2ABCE0', 'rank': 'normal'})], 'P2534': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2534', 'datatype': 'math', 'datavalue': {'value': '\\displaystyle v=f\\lambda', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$56A1C229-714C-4B88-899E-9BA2DADAB332', 'rank': 'normal', 'references': [{'snaks': {'P143': [{'snaktype': 'value', 'property': 'P143', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 328}, 'type': 'wikibase-entityid'}}]}, 'snaks-order': ['P143'], 'hash': 'fa278ebfc458360e5aed63d5058cca83c46134f1'}]})], 'P156': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P156', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 3151}, 'type': 'wikibase-entityid'}}, 'type': 'statement', 'id': 'Q2225$c043582b-4f1a-c273-755b-870120f59ba9', 'rank': 'normal', 'qualifiers': {'P642': [{'snaktype': 'value', 'property': 'P642', 'datatype': 'wikibase-item', 'datavalue': {'value': {'entity-type': 'item', 'numeric-id': 846671}, 'type': 'wikibase-entityid'}, 'hash': '70a76205a395caadf5346c218a4af722dcd40506'}]}, 'qualifiers-order': ['P642']})], 'P155': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'novalue', 'property': 'P155'}, 'type': 'statement', 'id': 'Q2225$36f78ba3-4d6f-f6a3-2adf-df5a9bae6e74', 'rank': 'normal'})], 'P1417': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P1417', 'datatype': 'external-id', 'datavalue': {'value': 'science/electron', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$43B0B42C-C1C5-43F3-A097-4406B26D6335', 'rank': 'normal'})], 'P665': [Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P665', 'datatype': 'external-id', 'datavalue': {'value': 'C05359', 'type': 'string'}}, 'type': 'statement', 'id': 'Q2225$F6B098BA-1C3F-4064-AFA5-1AB8C218B164', 'rank': 'normal'})]}
clm_list = clm_dict["P2069"]

for clm in clm_list:
    print(clm)
Claim.fromJSON(DataSite("wikidata", "wikidata"), {'mainsnak': {'snaktype': 'value', 'property': 'P2069', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '-1.00115965218076', 'upperBound': '-1.00115965218075', 'lowerBound': '-1.00115965218077', 'unit': 'http://www.wikidata.org/entity/Q737120'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$edaaaf4e-48fd-6503-016c-27d857e55f40', 'rank': 'normal'})
import pywikibot

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

item_dict = item.get()
clm_dict = item_dict["claims"]
clm_list = clm_dict["P2069"]

for clm in clm_list:
    print(clm.toJSON())
{'mainsnak': {'snaktype': 'value', 'property': 'P2069', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '-1.00115965218076', 'upperBound': '-1.00115965218075', 'lowerBound': '-1.00115965218077', 'unit': 'http://www.wikidata.org/entity/Q737120'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$edaaaf4e-48fd-6503-016c-27d857e55f40', 'rank': 'normal'}
import pywikibot

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

item_dict = item.get()
clm_dict = item_dict["claims"]
clm_list = clm_dict["P2069"]

for clm in clm_list:
    print(clm.toJSON())
{'mainsnak': {'snaktype': 'value', 'property': 'P2069', 'datatype': 'quantity', 'datavalue': {'value': {'amount': '-1.00115965218076', 'upperBound': '-1.00115965218075', 'lowerBound': '-1.00115965218077', 'unit': 'http://www.wikidata.org/entity/Q737120'}, 'type': 'quantity'}}, 'type': 'statement', 'id': 'Q2225$edaaaf4e-48fd-6503-016c-27d857e55f40', 'rank': 'normal'}
for clm in clm_list:
    ...
    clm_trgt = clm.getTarget()
    print(clm_trgt)
    print(type(clm_trgt))
    print(dir(clm_trgt))
{
    "amount": "-1.00115965218076",
    "lowerBound": "-1.00115965218077",
    "unit": "http://www.wikidata.org/entity/Q737120",
    "upperBound": "-1.00115965218075"
}
<class 'pywikibot.WbQuantity'>
['__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__', '__weakref__', '_fromdecimal', '_items', '_require_errors', '_todecimal', '_unit', 'amount', 'fromWikibase', 'get_unit_item', 'lowerBound', 'site', 'toWikibase', 'unit', 'upperBound']
import pywikibot

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

item_dict = item.get()
clm_dict = item_dict["claims"]
clm_list = clm_dict["P2069"]

for clm in clm_list:
    clm_trgt = clm.getTarget()
    print(clm_trgt.amount)
    print(clm_trgt.unit)
-1.00115965218076
http://www.wikidata.org/entity/Q737120
from collections import OrderedDict
import pywikibot
import csv

site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)

item_dict = item.get()
lbl_dict = item_dict["labels"]
lbl_sdict = OrderedDict(sorted(lbl_dict.items())) #Sorting the dictionary

with open("output_douglas.csv", "w", newline="", encoding='utf-8') as csvf:
    fields = ["lang-code", "label"]
    writer = csv.DictWriter(csvf, fieldnames=fields)
    writer.writeheader()
    for key in lbl_sdict:
        writer.writerow({"lang-code": key, "label": lbl_sdict[key]})
import pywikibot
import json

site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)

item_dict = item.get()
lbl_dict = item_dict["labels"]

with open("output_douglas.json", "w", newline="", encoding='utf-8') as jsonf:
    json.dump(lbl_dict, jsonf, ensure_ascii=False, sort_keys=True)
import pywikibot
import sqlite3

site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)

item_dict = item.get()
lbl_dict = item_dict["labels"]

conn = sqlite3.connect('output-douglas.db')
c = conn.cursor()
c.execute('''CREATE TABLE labels
             (langcode text, label text)''')

for key in lbl_dict:
    row = [key, lbl_dict[key]]
    c.execute("INSERT INTO labels VALUES (?, ?)", row)

conn.commit()
conn.close()
import pywikibot

from pywikibot import pagegenerators as pg

def list_template_usage(site_obj, tmpl_name):
    """
    Takes Site object and template name and returns a generator.

    The function expects a Site object (pywikibot.Site()) and
    a template name (String). It creates a list of all
    pages using that template and returns them as a generator.
    The generator will load 50 pages at a time for iteration.
    """
    name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
    tmpl_page = pywikibot.Page(site_obj, name)
    ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)
    filter_gen = pg.NamespaceFilterPageGenerator(ref_gen, namespaces=[0])
    generator = site_obj.preloadpages(filter_gen, pageprops=True)
    return generator

site = pywikibot.Site("en", 'wikipedia')
tmpl_gen = list_template_usage(site, "Infobox meteorite")

for page in tmpl_gen:
    item = pywikibot.ItemPage.fromPage(page)
    print(page.title(), item.getID())
Retrieving 50 pages from wikipedia:en.
Wold Cottage meteorite Q4053207
Allan Hills 84001 Q47580
Campo del Cielo Q1031478
Sayh al Uhaymir 169 Q2228546
Sikhote-Alin meteorite Q652204
Willamette Meteorite Q962600
Heat Shield Rock Q610553
Canyon Diablo (meteorite) Q1034024
High Possil meteorite Q5756223
Orgueil (meteorite) Q3131804
Cape York meteorite Q1034516
Murchison meteorite Q1164183
Imilac Q6004059
Paragould meteorite Q7134640
Old Woman meteorite Q4045713
Tagish Lake (meteorite) Q1640697
Hoba meteorite Q216876
Kaidun meteorite Q1298625
Fukang (meteorite) Q5507580
Chassigny (meteorite) Q174066
Nakhla meteorite Q1082769
Yamato 791197 Q8047974
Shergotty meteorite Q2975736
Chinguetti meteorite Q5101045
Karoonda meteorite Q1626872
Adelie Land meteorite Q355052
Hadley Rille meteorite Q261837
Peekskill meteorite Q1477392
Beardsley meteorite Q4876692
Bench Crater meteorite Q2895690
Allende meteorite Q1930079
Stannern (meteorite) Q1968101
Gibeon (meteorite) Q1522908
Sylacauga (meteorite) Q2564923
Brahin (meteorite) Q897277
Esquel (meteorite) Q5399225
Brenham (meteorite) Q4096315
Homestead (meteorite) Q4040725
L'Aigle (meteorite) Q1880589
Krasnojarsk (meteorite) Q427535
Huckitta (meteorite) Q5928087
Monte Milone (meteorite) Q15255597
Omolon (meteorite) Q4334665
Mineo (meteorite) Q3858361
Norton County (meteorite) Q4045484
Ourique (meteorite) Q15264763
Pultusk (meteorite) Q4047637
Pavlovka (meteorite) Q3583079
Qidong (meteorite) Q7267696
Park Forest (meteorite) Q5971067
Retrieving 50 pages from wikipedia:en.
Gao–Guenie meteorite Q176241
Pallasovka (meteorite) Q7127754
Seymchan (meteorite) Q2275869
Ensisheim (meteorite) Q1344365
Albareto (meteorite) Q3607897
Buzzard Coulee meteorite Q5003569
Tenham (meteorite) Q7699844
Mbozi meteorite Q4382614
Bovedy (meteorite) Q4950516
Chergach Q5091898
Yardymly (meteorite) Q4538523
Kesen meteorite Q1966720
Abee (meteorite) Q318284
Adhi Kot (meteorite) Q4682525
Appley Bridge meteorite Q4781441
Aarhus (meteorite) Q3583039
Andura Q4760315
Archie (meteorite) Q4786601
Agen (meteorite) Q4691978
Allegan (meteorite) Q4731221
Ambapur Nagla Q4741017
Anlong (meteorite) Q4766142
Arbol Solo (meteorite) Q4784741
Arroyo Aguiar (meteorite) Q4796226
Assisi (meteorite) Q4808928
Akbarpur (meteorite) Q4700483
Ankober (meteorite) Q4766088
Avanhandava (meteorite) Q4827653
Chambord meteorite Q5069701
Neuschwanstein (meteorite) Q1981433
St-Robert meteorite Q7586657
Penouille meteorite Q15265917
Lac Dodon Q45069383
Veliky Ustyug (meteorite) Q4106567
Weston meteorite Q4053060
Elbogen (meteorite) Q4037970
Moss meteorite Q6916610
Annaheim meteorite Q4767789
Oileán Ruaidh (Mars rock) Q7081488
Angers (meteorite) Q4763139
Springwater meteorite Q4049972
Benton meteorite Q4890639
Blithfield meteorite Q4926933
Osseo meteorite Q7107430
Gay Gulch meteorite Q5528588
Peace River (meteorite) Q7157430
Yamato 691 Q4537600
Middlesbrough meteorite Q6841881
Toluca (meteorite) Q1625058
Adzhi-Bogdo Q4686953
Retrieving 50 pages from wikipedia:en.
Hraschina meteorite Q728624
Muonionalusta Q6937085
Claxton meteorite Q4984880
Tissint meteorite Q3333926
Treysa (meteorite) Q875469
Sutter's Mill meteorite Q1587292
Goose Lake meteorite Q4039603
Loreto (meteorite) Q6680892
Atoka meteorite Q4817176
Grant meteorite Q5596601
Chinga meteorite Q614594
Novato meteorite Q7064495
Dronino meteorite Q897501
Brachina meteorite Q4953288
Nantan meteorite Q351033
Zaklodzie meteorite Q144748
Eagle Station meteorite Q5325264
Itqiy meteorite Q1449768
Tamdakht meteorite Q1532797
Santa Vitoria do Palmar meteorite Q1591644
Tlacotepec meteorite Q7810691
Richardton meteorite Q1364761
Příbram meteorite Q939754
Bellsbank meteorite Q4884167
Oldenburg meteorite Q1971281
Northwest Africa 3009 Q1240766
Twannberg meteorite Q1542807
Coahuila meteorite Q4036340
Cranbourne meteorite Q1138829
Vermillion meteorite Q7921633
Winona meteorite Q8025899
Angra dos Reis meteorite Q4763888
Northwest Africa 7034 Q2596468
Ornans (meteorite) Q7103521
Shelter Island meteorite Q4049389
Block Island meteorite Q4035204
Mackinac Island meteorite Q4043551
D'Orbigny meteorite Q5203167
Mundrabilla (meteorite) Q6935888
Millbillillie (meteorite) Q1169408
Gebel Kamil (meteorite) Q5529550
Zaisho Q8064892
Kainsaz meteorite Q1721470
Polonnaruwa (meteorite) Q7225953
Chelyabinsk meteorite Q4980823
Sołtmany (meteorite) Q4985109
Baszkówka (meteorite) Q4984351
Białystok (meteorite) Q4985106
Łowicz (meteorite) Q4043234
Allan Hills A81005 Q5379096
Retrieving 26 pages from wikipedia:en.
Sulagiri (meteorite) Q7635946
Northwest Africa 7325 Q4162207
Yamato 000593 Q15888151
Bacubirito Meteorite Q18209819
Santa Rosa de Viterbo Meteorite Q18354908
Lake Murray Meteorite Q18154197
Port Orford meteorite hoax Q23018424
Österplana 065 Q24658624
Los Angeles (meteorite) Q25006284
Zagami meteorite Q9385821
Gancedo (meteorite) Q26878625
Mason Gully (meteorite) Q39069888
Murrili Meteorite Q39057567
Dingle Dell Meteorite Q39057579
Bendegó meteorite Q4035016
Dimmitt (meteorite) Q55609607
El Boludo (meteorite) Q55610643
El Tiro (meteorite) Q55610658
Varre-Sai meteorite Q55886468
Serra Pelada (meteorite) Q55886806
Marília (meteorite) Q55886820
Patos de Minas (meteorite) Q55886913
Albin (meteorite) Q55888190
---------------------------------------------------------------------------
NoPage                                    Traceback (most recent call last)
<ipython-input-27-f6066879be42> in <module>()
     23 
     24 for page in tmpl_gen:
---> 25     item = pywikibot.ItemPage.fromPage(page)
     26     print(page.title(), item.getID())

/srv/paws/pwb/pywikibot/page.py in fromPage(cls, page, lazy_load)
   4343         i._title = page.title(with_section=False)
   4344         if not lazy_load and not i.exists():
-> 4345             raise pywikibot.NoPage(i)
   4346         page._item = i
   4347         return page._item

NoPage: Page [[wikidata:-1]] doesn't exist.
#Items that have a pKa value set
SELECT ?item ?value
WHERE 
{
	?item wdt:P1117 ?value .
}
  File "<ipython-input-28-af9b09fc6ecd>", line 2
    SELECT ?item ?value
           ^
SyntaxError: invalid syntax
import pywikibot
from pywikibot import pagegenerators as pg

with open('pka-query.rq', 'r') as query_file:
    QUERY = query_file.read()

wikidata_site = pywikibot.Site("wikidata", "wikidata")
generator = pg.WikidataSPARQLPageGenerator(QUERY, site=wikidata_site)

for item in generator:
    print(item)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-29-fe6410ac9dff> in <module>()
      3 from pywikibot import pagegenerators as pg
      4 
----> 5 with open('pka-query.rq', 'r') as query_file:
      6     QUERY = query_file.read()
      7 

FileNotFoundError: [Errno 2] No such file or directory: 'pka-query.rq'