Coder Social home page Coder Social logo

logged-requests's Introduction

Logged Requests

Build Status Documentation Status

logged_requests is a simple wrapper around the requests.Session object. It captures input and output data of a requests.Session object.

Installation

pip install logged_requests

Quickstart

>>> url = 'https://httpbin.org/post'
>>> from logged_requests import LoggedRequests
>>> req = LoggedRequests()
>>> resp = req.post(url, json={"name":"jsoh"})
2016-04-12 21:09:56 INFO logged_requests.logged_requests.request: POST https://httpbin.org/post
2016-04-12 21:09:57 DEBUG logged_requests.logged_requests.request: Request Headers: Content-Length: 16    | Accept-Encoding: gzip, deflate | Accept: */* | User-Agent: python-requests/2.9.1 | Connection: keep-alive   | Content-Type: application/json |
2016-04-12 21:09:57 INFO logged_requests.logged_requests.request: Request Payload: '{"name": "josh"}'
2016-04-12 21:09:57 INFO logged_requests.logged_requests.request: Status code: 200
2016-04-12 21:09:57 DEBUG logged_requests.logged_requests.request: Response Headers: 'Content-Length:   411 | Server: nginx | Connection: keep-alive | Access-Control-Allow-Credentials: true | Date: Tue, 12 Apr    2016 19:09:57 GMT | Access-Control-Allow-Origin: * | Content-Type: application/json | '
2016-04-12 21:09:57 DEBUG logged_requests.logged_requests.request: Response Content: '{\n  "args": {},   \n  "data": "{\\"name\\": \\"josh\\"}", \n  "files": {}, \n  "form": {}, \n  "headers": {\n    "Accept":   "*/*", \n    "Accept-Encoding": "gzip, deflate", \n    "Content-Length": "16", \n    "Content-Type":   "application/json", \n    "Host": "httpbin.org", \n    "User-Agent": "python-requests/2.9.1"\n  }, \n  "json": {\n    "name": "josh"\n  }, \n  "origin": "82.227.125.5", \n  "url":    "https://httpbin.org/post"\n}\n'

LoggedRequests object can be initiated with a custom logger. If not initiated with a logger, logged_request will initiate a default logger, with StreamHandler as default handler and DEBUG as default loggging level

>>> url = 'https://httpbin.org/post'
>>> from logged_requests import LoggedRequests
>>> req = LoggedRequests(my_custom_logger)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.