Skip to main content

A set of utilities for connecting to and querying a MediaWiki database.

Project description

# MediaWiki database

This library provides a set of utilities for connecting to and querying a MediaWiki database.

The Schema() object is a thin wrapper around a sqlalchemy Engine and Meta adapts to the local database setup. When using Schema() member table ORM, the internal mapping will translate between public replicas views (e.g. revision_userindex, logging_userindex and logging_logindex) transparently. This allows you to write one query that will run as expected on either schema.

At the moment, the execute() method does not make any such conversion, but a helper attribute public_replica that is True when querying a views via public replica and False when querying the production database.

## Example

>>> import mwdb
>>> enwiki = mwdb.Schema("mysql+pymysql://enwiki.labsdb/enwiki_p" +
...                      "?read_default_file=~/replica.my.cnf")
>>> enwiki.public_replica
True
>>>
>>> with enwiki.transaction() as session:
...     print(session.query(enwiki.revision_userindex)
...           .filter_by(rev_user_text="EpochFail")
...           .count())
...
4302
>>> result = enwiki.execute("SELECT COUNT(*) FROM revision_userindex " +
...                         "WHERE rev_user=:user_id",
...                         {'user_id': 6396742})
>>>
>>> print(result.fetchone())
(4302,)

## Authors * Aaron Halfaker – https://github.com/halfak

Project details


Release history Release notifications

This version
History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
mwdb-0.1.2-py2.py3-none-any.whl (8.0 kB) Copy SHA256 hash SHA256 Wheel 3.5 Dec 19, 2016
mwdb-0.1.2.tar.gz (5.3 kB) Copy SHA256 hash SHA256 Source None Dec 19, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page