{ "info": { "author": "Natural History Museum", "author_email": "data@nhm.ac.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Utilities" ], "description": "# pyportal\n\nA Python wrapper around the API for the Natural History Museum's [Data Portal](https://data.nhm.ac.uk).\n\nThis module is new and under development, so does not include all actions available through the API; it prioritises the record search functionality. It is liable to change dramatically between versions.\n\nWe have more generic (and comprehensive) API documentation available [here](https://naturalhistorymuseum.github.io/dataportal-docs).\n\n\n## Requirements\n\n- Python 3.7+\n\n\n## Installation\n\n```sh\npip install -e git+git://github.com/NaturalHistoryMuseum/nhm-pyportal.git#egg=pyportal\n```\n\n\n## Quickstart Usage\n\nStart by creating an `API` object:\n\n```python\nimport pyportal\n\napi = pyportal.API()\n```\n\n### Searching\n\nYou can either search for all records, or specifically for assets/media. The syntax is very similar for both.\n\n```python\nfrom pyportal import constants\n\n# specify any resource you want, but the IDs for the specimens and index lots resources are built in\nresource_id = constants.resources.specimens\n\n# find all records in the specimens resource\nsearch = api.records(resource_id)\n\n# OR find all assets (images) in the specimens resource\nsearch = api.assets(resource_id)\n```\n\nThe search above is equivalent to [this search](https://data.nhm.ac.uk/dataset/56e711e6-c847-4f99-915a-6894bb5c5dea/resource/05ff2255-c38a-40c9-b657-4ccb55ab2feb) on the Data Portal website.\n\nThere is a helper method to transform a data portal URL into a `dict` that can be passed into the search constructor.\n\n```python\nurl = 'https://data.nhm.ac.uk/dataset/56e711e6-c847-4f99-915a-6894bb5c5dea/resource/05ff2255-c38a-40c9-b657-4ccb55ab2feb?filters=collectionCode%3Abot'\n\n# these two searches are equivalent\n\nprint(api.records(constants.resources.specimens, collectionCode='bot').count()) # 775440\n\nprint(api.records(**api.from_url(url)).count()) # 775440\n```\n\nYou can specify the following parameters (all are optional):\n\n- `query`: a free-text search, e.g. `query='bugs'`\n- `sort`: a list of fields and sort directions, e.g. `sort=['country asc', 'family desc']`\n- `fields`: a list of fields to return for each record (leave blank to return all), e.g. `fields=['country', 'family', 'genus']`\n- `offset`: skip the first _n_ results, e.g. `offset=50`\n- `limit`: return only _n_ results _per page_ (defaults to 100), e.g. `limit=10`\n\nAny other keyword arguments will be considered `filters`.\n\n```python\nsearch = api.records(constants.resources.specimens, query='bugs', sort=['country asc', 'family desc'], fields=['country', 'family', 'genus'], offset=50, limit=10)\n```\n\n### Viewing results\n\nIterate through all results using `.all()` (this ignores `limit`):\n\n```python\nfor record in search.all():\n print(record)\n```\n\nOr just view the first one with `.first()`:\n\n```python\nprint(search.first())\n```\n\nYou could also view a page (blocks of records in the size set by `limit`) at a time using `.next()`:\n\n```python\ntry:\n page = search.next()\n for record in page:\n print(record)\nexcept StopIteration: # raised by search.next() if there's no next page\n print('No more results.')\n```\n\nIf you just want the total number of records, use `.count()`:\n\n```python\nprint(search.count())\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/NaturalHistoryMuseum/nhm-pyportal", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "nhm-pyportal", "package_url": "https://pypi.org/project/nhm-pyportal/", "platform": "", "project_url": "https://pypi.org/project/nhm-pyportal/", "project_urls": { "Homepage": "https://github.com/NaturalHistoryMuseum/nhm-pyportal" }, "release_url": "https://pypi.org/project/nhm-pyportal/0.1/", "requires_dist": [ "requests" ], "requires_python": "", "summary": "", "version": "0.1" }, "last_serial": 5995918, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b6335ae6b6d314b23cddbaa9757f761b", "sha256": "c37ec0c5e0b0199eaeba8d22314696efdf2259d352ec27890d982d2793bf18a2" }, "downloads": -1, "filename": "nhm_pyportal-0.1-py3.7.egg", "has_sig": false, "md5_digest": "b6335ae6b6d314b23cddbaa9757f761b", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 7205, "upload_time": "2019-10-18T14:27:44", "url": "https://files.pythonhosted.org/packages/17/23/66cfa2bc1bcbee6dfbee0cabe6b40c56de91436134edd8680713a2515dca/nhm_pyportal-0.1-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "c35d283be8d95eb94ea163f959d1f1e2", "sha256": "b583336bc87ddd7bf3ceb49d845e80c4b1798a5d5217d29b5d347cb8fe6ff356" }, "downloads": -1, "filename": "nhm_pyportal-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "c35d283be8d95eb94ea163f959d1f1e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7515, "upload_time": "2019-10-18T14:27:39", "url": "https://files.pythonhosted.org/packages/03/13/eb76bc8c33a1c9264fc016ed92784add3dc61fa8679b348006c627adad21/nhm_pyportal-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8a3f4964485a826c0389483a2ff7db5e", "sha256": "ceac4f5584564aab139b8e3fd3fdfb679add2a8a9d24c68b15ffda324b1c25d0" }, "downloads": -1, "filename": "nhm-pyportal-0.1.tar.gz", "has_sig": false, "md5_digest": "8a3f4964485a826c0389483a2ff7db5e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6170, "upload_time": "2019-10-18T14:27:43", "url": "https://files.pythonhosted.org/packages/e1/8c/4712e310a70f51af3af38c4d9c7e2946525673fd5b584e276f928d186b97/nhm-pyportal-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b6335ae6b6d314b23cddbaa9757f761b", "sha256": "c37ec0c5e0b0199eaeba8d22314696efdf2259d352ec27890d982d2793bf18a2" }, "downloads": -1, "filename": "nhm_pyportal-0.1-py3.7.egg", "has_sig": false, "md5_digest": "b6335ae6b6d314b23cddbaa9757f761b", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 7205, "upload_time": "2019-10-18T14:27:44", "url": "https://files.pythonhosted.org/packages/17/23/66cfa2bc1bcbee6dfbee0cabe6b40c56de91436134edd8680713a2515dca/nhm_pyportal-0.1-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "c35d283be8d95eb94ea163f959d1f1e2", "sha256": "b583336bc87ddd7bf3ceb49d845e80c4b1798a5d5217d29b5d347cb8fe6ff356" }, "downloads": -1, "filename": "nhm_pyportal-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "c35d283be8d95eb94ea163f959d1f1e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7515, "upload_time": "2019-10-18T14:27:39", "url": "https://files.pythonhosted.org/packages/03/13/eb76bc8c33a1c9264fc016ed92784add3dc61fa8679b348006c627adad21/nhm_pyportal-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8a3f4964485a826c0389483a2ff7db5e", "sha256": "ceac4f5584564aab139b8e3fd3fdfb679add2a8a9d24c68b15ffda324b1c25d0" }, "downloads": -1, "filename": "nhm-pyportal-0.1.tar.gz", "has_sig": false, "md5_digest": "8a3f4964485a826c0389483a2ff7db5e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6170, "upload_time": "2019-10-18T14:27:43", "url": "https://files.pythonhosted.org/packages/e1/8c/4712e310a70f51af3af38c4d9c7e2946525673fd5b584e276f928d186b97/nhm-pyportal-0.1.tar.gz" } ] }