{"id":16293019,"url":"https://github.com/kimmobrunfeldt/nap","last_synced_at":"2025-03-16T13:31:34.001Z","repository":{"id":12541353,"uuid":"15211415","full_name":"kimmobrunfeldt/nap","owner":"kimmobrunfeldt","description":"Convenient way to request HTTP APIs","archived":false,"fork":false,"pushed_at":"2022-12-26T19:43:37.000Z","size":110,"stargazers_count":42,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-13T03:00:22.544Z","etag":null,"topics":["api","http","http-api","python","requests"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kimmobrunfeldt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-15T21:47:36.000Z","updated_at":"2023-08-18T13:39:57.000Z","dependencies_parsed_at":"2023-01-13T17:00:22.990Z","dependency_job_id":null,"html_url":"https://github.com/kimmobrunfeldt/nap","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmobrunfeldt%2Fnap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmobrunfeldt%2Fnap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmobrunfeldt%2Fnap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmobrunfeldt%2Fnap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimmobrunfeldt","download_url":"https://codeload.github.com/kimmobrunfeldt/nap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243817170,"owners_count":20352506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","http","http-api","python","requests"],"created_at":"2024-10-10T20:09:45.207Z","updated_at":"2025-03-16T13:31:33.520Z","avatar_url":"https://github.com/kimmobrunfeldt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nap\n\n[![Build Status](https://travis-ci.org/kimmobrunfeldt/nap.png?branch=master)](https://travis-ci.org/kimmobrunfeldt/nap)\n[![Coverage Status](https://coveralls.io/repos/kimmobrunfeldt/nap/badge.png?branch=master)](https://coveralls.io/r/kimmobrunfeldt/nap?branch=master)\n[![Badge fury](https://badge.fury.io/py/nap.png)](https://badge.fury.io/py/nap.png)\n[![Badge PyPi](https://pypip.in/d/nap/badge.png)](https://pypip.in/d/nap/badge.png)\n\n*Nap* provides convenient way to request HTTP APIs.\nAfter coding a few HTTP API wrapper classes, I decided to code *Nap*.\nIt's is just a small(*~150 loc*) wrapper around [requests][].\nRequests is a superb HTTP library, which supports everything you'll need to get things done in today's web.\n\n**Example**\n\n```python\nfrom nap.url import Url\napi = Url('https://api.github.com/')\n# GET https://api.github.com/users\napi.get('users')\n\nusers = api.join('users')\n# GET https://api.github.com/users/kimmobrunfeldt\nusers.get('kimmobrunfeldt')\n\n# Another way to make the same request as above:\napi.get('users/kimmobrunfeldt')\n```\n\n**Get started**\n\n* Look through [examples](#examples)\n* See [API documentation](docs/nap-api.md)\n* [Dive into code](nap/url.py)\n\n\n## Install\n\nPython versions 2.7, 3.6, 3.7, 3.8 and PyPy are supported and tested against.\n\nInstall latest release with *pip*:\n\n    pip install nap\n\nInstall latest development version usin *pip*:\n\n    pip install git+git://github.com/kimmobrunfeldt/nap.git\n\nInstall latest development version using *setup.py*:\n\n    git clone git@github.com:kimmobrunfeldt/nap.git\n    cd nap\n    python setup.py install\n\n## Nap API documentation\n\nSee [API documentation](docs/nap-api.md)\n\n## Examples\n\nFind gists from GitHub.\n\n```python\nfrom nap.url import Url\napi = Url('https://api.github.com/')\n\n# Get gists since May 1st 2014 (will be paginated)\ngists = api.get('gists', params={'since': '2014-05-01T00:00:00Z'})\nprint(gists.json())\n```\n\nYou can also specify default keyword arguments to be passed on every request in *Url* initialization.\nAll authentications supported by *requests* are automatically supported.\n\n```python\nfrom nap.url import Url\n# Keyword arguments given to Url will be given to each request method\n# by default for every request.\napi = Url('https://api.github.com/', auth=('user', 'pass'))\n\n# Get authenticated user\nresponse = api.get('user')\nprint(response.json())\n\n# You can also override the default keyword arguments afterwords\nresponse = api.get('users/kimmobrunfeldt', auth=('kimmo', 'password1'))\n```\n\n**A bit more complicated example.**\nAutomatically convert all JSON responses to Python dict objects.\nDemonstrate various HTTP methods.\nAlso raise errors from other than `200 OK` responses.\n\n```python\nfrom nap.url import Url\nimport requests\n\nclass JsonApi(Url):\n    def after_request(self, response):\n        if response.status_code != 200:\n            response.raise_for_status()\n\n        return response.json()\n\n# Use https://github.com/kennethreitz/httpbin for testing\napi = JsonApi('http://httpbin.org/')\n\n# response is dict object containing parsed JSON\nresponse = api.post('post', data={'test': 'Test POST'})\nprint(response)\n\nresponse = api.put('put', data={'test': 'Test PUT'})\nprint(response)\n\ntry:\n    # httpbin will response with `Method Not Allowed` if we try to do\n    # POST http://httpbin.org/get\n    api.post('get')\nexcept requests.exceptions.HTTPError as e:\n    print('Response was not OK, it was: %s' % e.response.status_code)\n```\n\n\n## Contributing\n\n[Documentation for Nap developers](docs/)\n\n[requests]: http://docs.python-requests.org/en/latest/     \"Requests\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimmobrunfeldt%2Fnap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimmobrunfeldt%2Fnap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimmobrunfeldt%2Fnap/lists"}