Skip to main content

======================================== 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 asyncio
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()
print((sql, params))
loop = asyncio.get_event_loop()
result_list = loop.run_until_complete(app['mysql'].get_all(sql,params))
print(result_list)
app.stop()

Redis

.. code-block:: python

from tomato.util import Application
from tomato.store import RedisModule


app = Application()
app['redis'] = RedisModule(setting=redis_setting)
app.run()
redis = RedisController()
loop = asyncio.get_event_loop()
loop.run_until_complete(redis.set('my-key', 'my-value'))
assert loop.run_until_complete(redis.get('my-key')) == 'my-value'
app.stop()

Example

  • server <https://github.com/tangmi001/tomatolib/tree/master/examples>_

  • mysql <https://github.com/tangmi001/tomatolib/blob/master/tomato/store/mysql/sql_clause_assemble.py>_

Dependent library

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

Other contributors

Release files for tomatolib 0.4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tomatolib 0.4.5
File Size Uploaded
tomatolib-0.4.5.tar.gz 17.1 kB Details

Release files / tomatolib-0.4.5.tar.gz

Download URL tomatolib-0.4.5.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cc1e49be2d443c704adfcc3141bdaf7d07c4feaddea8fac59baa78e99f38e34a
BLAKE2b-256 checksum
How to use checksums
4c5e6198dbffaf90a7f9c287d28b43167aa45e1c42e5468a120d414e2f4eefa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.3

Release history Release notifications | RSS feed

This release

0.4.5 This release

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.0

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page