Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Super basic HTTP server for creating and testing REST APIs

Project Description

HTTP server in a single Python file. Offers a Python decorator to register functions for URL resources using regular expressions we all know and love.* Handy for trying out your future REST api ideas.

  • Written in a single .py file
  • No extra libraries needed
  • HTTPS
  • Uses Python logging module
  • Self documenting API index at / when you use docstrings on the handlers.
  • /yahs/reload reloads any module(s) that register any handlers to save stopping/starting server
  • Basic Cross-Origin Resource Sharing (CORS) responses enabled for all request types

Probably not better than Django, Flask, Jersey or other framework :P

Installation

Using pip

pip install yahs

Manual Install

python setup.py install

Sample Usage

from yahs import Server, Response
@Server.handle('GET', '^/food$')
def get_food(request):
    return "Hello there, here's some food!"

@Server.handle('GET', r'/products/(?P<product_id>[0-9]+)')
def get_product_by_id(request, product_id):
    """Gets a product by numeric id.
    E.g /products/240
    The regex named group/backreference 'product_id' will get added to the call when
    someone requests the matching url pattern. It will have the value 240.
    """
    response = Response()
    response.body = "<h1>Yo here it is... Product: #{}</h1>".format(product_id)
    return response

server = Server()  # default port is 4321
server.start()
server.wait()  # blocks the program from exiting early for short lived programs

License

MIT License

Do-maybe-list

  • Support class based Resource decorators with get, post, delete etc methods.

**Results may vary depending on how much you know and love regular expressions.*

Release History

Release History

This version
History Node

1.1

History Node

1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
yahs-1.1.tar.gz (7.8 kB) Copy SHA256 Checksum SHA256 Source Jun 17, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting