Giter Club home page Giter Club logo

status's Introduction

status - HTTP Status for Humans

version supported license

status is a very simple python library which provides human understandable HTTP status codes and improves readability of your code. You don't have to use those ugly HTTP status numbers, but use easily understandable status names.

Don't:

class PythonPeople(RequestHandler):
    def post(self):
        # do stuff
        return ('That worked!', 201)

But, do this:

class PythonPeople(RequestHandler):
    def post(self):
        # do stuff
        return ('That worked!', status.HTTP_201_CREATED)

See, that looks so much better. You can use this library wherever you want, from custom python scripts to Django, Flask etc apps. For example, if you were playing with Requests:

>>> response = requests.delete('http://some-url')
>>> response.status_code == status.HTTP_204_NO_CONTENT

Installation

pip install python-status

Usage

status comes with HTTP response status codes and also some helpful methods to check the response status. Under the hood, status codes are merely an integer variable with meaningful variable names. Check status.py file.

>>> import status
>>> status.HTTP_200_OK == 200
True

For list of available status codes check status.py file.

status also comes with some helpful methods to check the status of a response. They are status.is_informational, status.is_success, status.is_redirect, status.is_client_error and status.is_server_error.

>>> import status
>>> response = requests.delete('http://some-url')
>>> if status.is_success(code=response.status_code):
        print('yay!')
>>> 
yay!

Why?

For every project I was creating a status.py file in the root directory. So I thought it's better to release this as a package on PyPi and use it.

Alternatives

Starting with Python 3.5, the standard library includes HTTP Status enum.

License

Please check LICENSE for more details.

Credits

status is a fork of Django Rest Framework(DRF) and is independently maintained. The fork is entirely stripped of all DRF features and is not a submodule of DRF. And it doesn't come with any DRF functionalities.

status's People

Contributors

avinassh avatar davidbgk avatar harryhaos avatar kracekumar avatar pdex avatar ryansb avatar sriram-mv avatar vaibhavmule avatar

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.