Clone this wiki locally
Functions which take a namespace argument in mwclient, as well as data members such as Page.namespace, express it in the form of an integer, the ''namespace index''. Built-in standard MediaWiki namespaces, including the article, user, project, file, template, category, help, and MediaWiki namespaces and their associated discussion pages, have fixed indexes associated with them, and are listed at Manual:Namespace.
site = mwclient.Site('en.wikipedia.org') print site.namespaces
Given a namespace index, the name can be retrieved by indexing into Site.namespaces:
page = site.Pages['Portal talk:Contents'] print site.namespaces[page.namespace] # Prints 'Portal talk'
By inverting this mapping, you can also easily refer to namespaces by name, as in this sample which lists all pages in the Portal talk namespace (a custom namespace on Wikipedia):
nsindexes = dict((v,k) for k,v in site.namespaces.iteritems()) for page in site.allpages(namespace=nsindexes['Portal talk']): print page.name