Skip to main content

Python Wrapper for the Yahoo ! Query Language

Project description


`|Build Status| <>`_
`|Documentation Status| <>`_ `|PyPI
version| <>`_ `|Join the chat at| <>`_
Issues| <>`_

MYQL is a Python wrapper of the Yahoo Query Language.

Yahoo! Query Language Documentation and Support

- Yahoo! Query Language -
- Yahoo! Developer Network:
- Yahoo! Application Platform -
- Yahoo! Social APIs -
- Yahoo! QUery Language Console

version 1.2

- OpenTable classes
- Access to resources requiring authentication

version 0.5.6

- fetch data
- access to community data
- select data format (xml/json)
- change data source
- filter data


- fix handling of default and on the fly response format
- fix limit on ***select(...).where(...)*** when no limit value is
- fix limit on ***get(...)***



$ pip install myql

how to use


>>> import myql
>>> yql = myql.MYQL()
>>> yql.diagnostics = True # To turn diagnostics on

access to community tables


>>> yql = myql.MYQL()
>>> rep = yql.rawQuery('desc ')
>>> rep.json()
{u'error': {u'lang': u'en-US', u'description': u'No definition found for Table'}}
>>> True # Setting up access to community
>>> rep = yql.rawQuery('desc ')
>>> rep.json()
{u'query': {u'count': 1, u'lang': u'en-US', u'results': {u'table': {u'src': u'', u'hash': u'061616a1c033ae89aaf2cbe83790b979', u'name': u'', u'request': {u'select': {u'key': {u'required': u'true', u'type': u'xs:string', u'name': u'symbol'}}}, u'meta': {u'sampleQuery': u'\n\t\t\tselect * from where symbol in ("YHOO","AAPL","GOOG","MSFT")\n\t\t'}, u'security': u'ANY'}}, u'created': u'2014-08-24T11:26:48Z'}}



>>> import myql
>>> yql = myql.MYQL(community=True)
>>> # do your magic

changing response format (xml or json)

The response format is by default ***json***.


>>> import myql
>>> yql = myql.MYQL(format='xml', community=True)
>>> rep = yql.rawQuery('select name, woeid from geo.states where place="Congo"')
>>> rep.text
u'<?xml version="1.0" encoding="UTF-8"?>\n<query xmlns:yahoo="" yahoo:count="11" yahoo:created="2014-08-27T04:52:22Z" yahoo:lang="en-US"><results><place xmlns=""><name>Cuvette-Ouest Department</name><woeid>55998384</woeid></place><place xmlns=""><name>Cuvette Department</name><woeid>2344968</woeid></place><place xmlns=""><name>Plateaux District</name><woeid>2344973</woeid></place><place xmlns=""><name>Sangha</name><woeid>2344974</woeid></place><place xmlns=""><name>Lekoumou</name><woeid>2344970</woeid></place><place xmlns=""><name>Pool Department</name><woeid>2344975</woeid></place><place xmlns=""><name>Likouala Department</name><woeid>2344971</woeid></place><place xmlns=""><name>Niari Department</name><woeid>2344972</woeid></place><place xmlns=""><name>Brazzaville</name><woeid>2344976</woeid></place><place xmlns=""><name>Bouenza Department</name><woeid>2344967</woeid></place><place xmlns=""><name>Kouilou</name><woeid>2344969</woeid></place></results></query><!-- total: 19 -->\n<!-- -->\n'
>>> rep = yql.rawQuery('select name, woeid from geo.states where place="Congo"', format='json')
>>> rep.json()
{u'query': {u'count': 11, u'lang': u'en-US', u'results': {u'place': [{u'woeid': u'55998384', u'name': u'Cuvette-Ouest Department'}, {u'woeid': u'2344968', u'name': u'Cuvette Department'}, {u'woeid': u'2344973', u'name': u'Plateaux District'}, {u'woeid': u'2344974', u'name': u'Sangha'}, {u'woeid': u'2344970', u'name': u'Lekoumou'}, {u'woeid': u'2344975', u'name': u'Pool Department'}, {u'woeid': u'2344971', u'name': u'Likouala Department'}, {u'woeid': u'2344972', u'name': u'Niari Department'}, {u'woeid': u'2344976', u'name': u'Brazzaville'}, {u'woeid': u'2344967', u'name': u'Bouenza Department'}, {u'woeid': u'2344969', u'name': u'Kouilou'}]}, u'created': u'2014-08-27T04:52:38Z'}}



Changes the data provider


>>> yql.use('')


Returns table description


>>> response = yql.desc('weather.forecast')
>>> response.json()
{u'query': {u'count': 1, u'lang': u'en-US', u'results': {u'table': {u'request': {u'select': [{u'key': [{u'required': u'true', u'type': u'xs:string', u'name': u'location'}, {u'type': u'xs:string', u'name': u'u'}]}, {u'key': [{u'required': u'true', u'type': u'xs:string', u'name': u'woeid'}, {u'type': u'xs:string', u'name': u'u'}]}]}, u'security': u'ANY', u'meta': {u'documentationURL': u'', u'sampleQuery': u'select * from weather.forecast where woeid=2502265', u'description': u'Weather forecast table', u'author': u'Yahoo! Inc'}, u'hash': u'aae78b1462a6a8fbc748aec4cf292767', u'name': u'weather.forecast'}}, u'created': u'2014-08-16T19:31:51Z'}}


Allows you to directly type your query


>>> response = yql.rawQuery("select * from geo.countries where place='North America'")
>>> # deal with the response

select(table, fields, limit).where(filters, ...)

Select a table i.e *weather.forecast*. If *table* not provided, it will
use the default table. If there's no such thing as a default table, it
will raise a *NoTableSelectedError*

***NB*** : A simple select doesn't return any data. Use ***GET***


>>> response ='geo.countries', [name, code, woeid]).where(['name', '=', 'Canada'])
>>> response.json()
{u'query': {u'count': 1, u'lang': u'en-US', u'results': {u'place': {u'woeid': u'23424775', u'name': u'Canada'}}, u'created': u'2014-08-16T19:04:08Z'}}
>>> ...
>>> rep ='geo.countries', ['name', 'woeid'], 2).where(['place', '=', 'Africa'])
>>> rep.json()
{u'query': {u'count': 2, u'lang': u'en-US', u'results': {u'place': [{u'woeid': u'23424740', u'name': u'Algeria'}, {u'woeid': u'23424745', u'name': u'Angola'}]}, u'created': u'2014-08-17T10:52:49Z'}}
>>> rep ='geo.countries', ['name', 'woeid'], 2).where(['place', 'in', ('Africa', 'Europe')])
>>> rep.json()
{u'query': {u'count': 2, u'lang': u'en-US', u'results': {u'place': [{u'woeid': u'23424740', u'name': u'Algeria'}, {u'woeid': u'23424745', u'name': u'Angola'}]}, u'created': u'2014-08-17T11:22:49Z'}}

get(table, fields, limit)

Same as ***SELECT***, but instead returns data.

**REMINDER** : Some tables require a **where clause**, therefore
***GET*** won't work on those tables, use *select(...).where(...)*
instead .


>>> yql.get('geo.countries', ['name', 'woeid'], 1)
>>> rep.json()
{u'query': {u'count': 1, u'lang': u'en-US', u'results': {u'place': {u'woeid': u'23424966', u'name': u'Sao Tome and Principe'}}, u'created': u'2014-08-17T10:32:25Z'}}

Using OAuth to fetch protected resources


>>> from myql.contrib.auth import YOAuth
>>> oauth = YOAuth(None, None, from_file='credentials.json') # only consumer_key and consumer_secret are required.
>>> from myql import MYQL
>>> yql = MYQL(format='xml', oauth=oauth)
>>> response = yql.getGUID('josue_brunel') # Deal with the response

.. |Build
Status| image::
.. |Documentation
Status| image::
.. |PyPI version| image::
.. |Join the chat at| image::
.. |Code
Issues| image::

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

myql-1.2.tar.gz (12.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page