Skip to main content

A quick and lightweight server framework.

Project description

======================================== Asynchronous server component library

.. image:: https://travis-ci.org/tangmi001/tomatolib.svg?branch=master :target: https://travis-ci.org/tangmi001/tomatolib :alt: Travis status for master branch

.. image:: https://codecov.io/gh/tangmi001/tomatolib/branch/master/graph/badge.svg :target: https://codecov.io/gh/tangmi001/tomatolib :alt: Codecov

.. image:: https://img.shields.io/github/license/tangmi001/tomatolib.svg :target: https://github.com/tangmi001/tomatolib/blob/master/LICENSE :alt: License

.. image:: https://img.shields.io/pypi/v/tomatolib.svg :target: https://pypi.org/project/tomatolib :alt: PyPI

Features

  • Manage common modules (MySQLModule, HttpServerModule) with Application class.
  • Web routing configures the handler through the decorator.
  • SQL normalization, avoiding heavy ORM, while also making readability.

Getting started

Server

An example using a server:

.. code-block:: python

# hello_handler.py

from aiohttp import web
from tomato.transport.http import Routes


routes = Routes()

@routes.get('/hello')
@routes.get('/hello/{name}')
async def xxx(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(text=text)

.. code-block:: python

# hello.py

from hello_handler import routes
from tomato.util import Application
from tomato.transport import HttpServerModule


app = Application()
app['http_server'] = HttpServerModule(host='localhost', port=1024, routes_list=[routes, ])
# app.run()
# app.stop()
app.run_forever()

MySQL

.. code-block:: python

import logging
from tomato.util import Application
from tomato.store import MySQLModule
from tomato.store import SqlClauseAssemble
from tomato.store import SqlParamCollections


app = Application()
# setting parameter is a dictionary type
app['mysql'] = MySQLModule(setting=mysql_setting)
app.run()
sql_assemble = SqlClauseAssemble()
sql_assemble.wanted_words = ['platform_id', 'open_id']
sql_assemble.table_name = '`app_account_users`'
where_params = SqlParamCollections()
where_params.add_normal_param(('open_id', '=', 18888888888, True))
sql_assemble.where_params = where_params
(sql, params) = sql_assemble.get_query_clause()
logging.info((sql, params))
result_list = loop.run_until_complete(app['mysql'].get_all(sql,params))
logging.info(result_list)
app.stop()

Example

please refer to examples <https://github.com/tangmi001/tomatolib/tree/master/examples>_.

Dependent library

  • aiohttp <https://github.com/aio-libs/aiohttp>_

Other contributors

Project details


Download files

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

Source Distribution

tomatolib-0.4.2.tar.gz (16.5 kB view details)

Uploaded Source

File details

Details for the file tomatolib-0.4.2.tar.gz.

File metadata

  • Download URL: tomatolib-0.4.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.3

File hashes

Hashes for tomatolib-0.4.2.tar.gz
Algorithm Hash digest
SHA256 dcbea96557e02534c319c93a8ce617d60d27b0e70f03ec0b456d2a5a15201d8b
MD5 ae768aa782e53a135a436e2cd260424c
BLAKE2b-256 9c79226396d7f6a19aacf2b1f625a8f1c1c0174e14fdb0d1cd0bd8643efa95b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page