{ "info": { "author": "Lucas Sampaio", "author_email": "lucas@lsmagalhaes.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Markup" ], "description": "GraphQL parser for Python\n=========================\n\nThis is an experimental, generic parser for the [GraphQL language][1] in Python. Consider it unstable since there's no spec for the language yey (that's why it's *experimental* ;)\n\n\nInstall and usage\n-----------------\n\n $ pip install graphql-python\n\nAnd just `import graphql` to get started. This library mimics the standard `json` module, so there's a `dumps` and a `loads` function. Consider this query:\n\n query = \"\"\"\n {\n user(232) {\n id,\n\t name,\n\t photo(size: 50) {\n\t url,\n width,\n height\n\t }\n\t }\n }\n \"\"\"\n\n objects = graphql.loads(query)\n # objects has now:\n [\n {\n\t \"name\": \"user\",\n\t \"params\": 232,\n\t \"properties\": [\n\t {\"name\": \"id\"},\n\t {\"name\": \"name\"},\n\t {\n\t\t \"name\": \"photo\",\n\t\t \"params\": {\"size\": 50},\n\t\t \"properties\": [\n\t\t {\"name\": \"url\"},\n\t\t {\"name\": \"width\"},\n\t\t {\"name\": \"height\"}\n\t\t ]\n\t\t },\n ]\n\t }\n ]\n\nTo understand how `loads` works, let's split this query into small parts:\n\n friends(user_id: 232).first(10) {\n url,\n name,\n address\n }\n\nThis query represents an *object* composed of:\n\n - a name (`friends`)\n - can be anything that matches the `r'`[a-zA-Z_][a-zA-Z0-9_/]*'` regex.\n - some parameters (`user_id: 232`)\n - can match literals (strings, numbers with or without signal, true, false and null) and pairs of values\n - `(true)` will be loaded as `\"params\": True`. Likewise, `(232)` will be `\"params\": 232`.\n - `(foo: \"bar\", bar: \"baz\")` will be loaded as `\"params\": {\"foo\": \"bar\", \"bar\": \"baz\"}`. Any valid identifier (the regex for *name*) can be used as an argument.\n - some custom filters (`first(10)`)\n - it's a sequence of identifiers followed by a list of parameters. Order is important, so for example, `.after(id: 243442).first(10)` will be loaded as:\n\n\n \"filters\": [\n (\"after\", {\"id\": 243442}),\n\t (\"first\", 10)\n ]\n\t\n\n - and a list of properties (`url, name, address`)... basically either an identifier or another nested object.\n\n\nSome advices\n------------\n\nRight now, this parser is *strict* (at least until the spec is released, obviously). It'll yell at you for not using commas in the right places. For example:\n\n # Will fail :(\n graphql.loads(\"\"\"\n user(42) {\n id,\n name\n \t}\n \"\"\")\n\n # Much better :) ... don't forget those { } in the beginning and end of the query \n graphql.loads(\"\"\"\n {\n user(42) {\n\t id,\n name\n \t}\n }\n \"\"\")\n\n # Will fail :(\n graphql.loads(\"\"\"\n {\n user(42) {\n id,\n name\n \t}\n\n company(2) {\n address\n \t}\n }\n \"\"\")\n\n # Much better :) ... see that little comma right after the first object?\n graphql.loads(\"\"\"\n {\n user(42) {\n \t id,\n \t name\n \t}, # <-- right here\n\n company(2) {\n \t address\n \t}\n }\n \"\"\")\n\n\nA note about performance & pyParsing\n------------------------------------\n\nI didn't test the numbers, just dropping [this link][2] for you to tell there's a way to improve pyParsing's performance.\nThis flag isn't enabled because it's global, so [YMMV][3].\n\n[1]: https://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html\n[2]: http://stackoverflow.com/a/21371472\n[3]: http://www.urbandictionary.com/define.php?term=ymmv\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lsmag/graphql-python", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "graphql-python", "package_url": "https://pypi.org/project/graphql-python/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/graphql-python/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/lsmag/graphql-python" }, "release_url": "https://pypi.org/project/graphql-python/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "Python implementation of GraphQL markup language", "version": "0.0.1" }, "last_serial": 1595987, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e26dc10fa2b9a4d153d282b0bd46ef09", "sha256": "c436ee0a6cba12c55011a60753f08d047ad3f5e6706b8a7158040acf98031c8b" }, "downloads": -1, "filename": "graphql-python-0.0.1.tar.gz", "has_sig": false, "md5_digest": "e26dc10fa2b9a4d153d282b0bd46ef09", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5411, "upload_time": "2015-06-17T14:49:59", "url": "https://files.pythonhosted.org/packages/5e/6a/b51deabe32550f3ebd2d3eeb337eed373c4b428b97f7c997ddf767c8eaea/graphql-python-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e26dc10fa2b9a4d153d282b0bd46ef09", "sha256": "c436ee0a6cba12c55011a60753f08d047ad3f5e6706b8a7158040acf98031c8b" }, "downloads": -1, "filename": "graphql-python-0.0.1.tar.gz", "has_sig": false, "md5_digest": "e26dc10fa2b9a4d153d282b0bd46ef09", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5411, "upload_time": "2015-06-17T14:49:59", "url": "https://files.pythonhosted.org/packages/5e/6a/b51deabe32550f3ebd2d3eeb337eed373c4b428b97f7c997ddf767c8eaea/graphql-python-0.0.1.tar.gz" } ] }