Skip to main content

Semantic Mediawiki Python Binding

Project description

Sematic MediaWiki Python binding

This package depends on the mwclient 0.7 development version

https://github.com/mwclient/mwclient.git

To install (will install mwclient 0.7dev automatically)

pip install smw

Or install from github

pip install git+git://github.com/baojie/smw.git

Usage example

from smw.SemanticMediaWiki import SemanticMediaWiki

# change this to your wiki's config
config = {
    "host": "www.foo.com",
    "path": "/wiki/",
    "http_login": None,
    "http_pass": None,
    "wiki_login": None,
    "wiki_pass": None,
}

wiki = SemanticMediaWiki(
    host=config["host"],
    path=config["path"],
    http_login=config["http_login"],
    http_pass=config["http_pass"],
    wiki_login=config["wiki_login"],
    wiki_pass=config["wiki_pass"])

# or from a config file (json)
# default ~/.smwrc
# sample config  https://github.com/baojie/smw/blob/master/smwrc.sample
wiki = SemanticMediaWiki.from_config()

query = r"""
{{#ask:
    [[SMW_PYTHON_TEST::+]]
|?SMW_PYTHON_TEST
|format = json
}}
"""

res = wiki.get_data(query, format='json')
[query_result, query_path] = res
# process query results from SMW >= 1.8.0
items = query_result['results']
for page in items:
    print items[page]

page_name = 'Foo'

# get page metadata in RDF/XML
rdf = wiki.getRDF(page_name)

# get page metadata in JSON, simplified for human readability
json_data = wiki.getJSON(page_name)

# parse any wiki script
result = wiki.parse("'''Hello'''")

# get raw page
# this is useful when query is composed on Special:Ask
html = wiki.get('/wiki/Main_Page')
json_result = wiki.get('/wiki/index.php?title=Special:Ask&q=[[Category:People]]&p[format]=json')

# add semantic annotations
page = wiki.site.Pages['SnowWhite']
old_content = page.edit()
new_content = old_content + "[[Category:Princess]][[friend of::Grumpy]]"
page.save(new_content)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smw-0.1.3.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

smw-0.1.3.3-py2.7.egg (10.3 kB view details)

Uploaded Source

File details

Details for the file smw-0.1.3.3.tar.gz.

File metadata

  • Download URL: smw-0.1.3.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for smw-0.1.3.3.tar.gz
Algorithm Hash digest
SHA256 c391f5071512a05dc172b3e75d94166fc034503031844210267b40c2bfa9f377
MD5 95e4cd536e8246f30434a634b3c057a7
BLAKE2b-256 0f88c73fc71e77a9c667502a96820d8bc6905a14c2a132f401c5fc3fe9b831b6

See more details on using hashes here.

File details

Details for the file smw-0.1.3.3-py2.7.egg.

File metadata

  • Download URL: smw-0.1.3.3-py2.7.egg
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for smw-0.1.3.3-py2.7.egg
Algorithm Hash digest
SHA256 2ef535c2a63c6dfb088bc7713f7a468a6a4a35c2008c3e26977afeff04954a98
MD5 3db2d7f94275ede1773e3693335cab08
BLAKE2b-256 7b65ec05ab00c58d2c99f78633aa6f959407a181b9800fcaf65a28caf46ba9fd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page