All Projects → feileo → helo

feileo / helo

Licence: MIT license
A simple and small low-level asynchronous ORM using Python asyncio.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to helo

synchronicity
Synchronicity lets you interoperate with asynchronous Python APIs.
Stars: ✭ 41 (+127.78%)
Mutual labels:  asyncio, await
kbio
Another Async IO Framework based on io_uring
Stars: ✭ 54 (+200%)
Mutual labels:  asyncio, await
Async Techniques Python Course
Async Techniques and Examples in Python Course
Stars: ✭ 314 (+1644.44%)
Mutual labels:  asyncio, await
aiosc
Lightweight Open Sound Control implementation for Python using asyncio
Stars: ✭ 26 (+44.44%)
Mutual labels:  asyncio
Promise.allSettled
ES Proposal spec-compliant shim for Promise.allSettled
Stars: ✭ 93 (+416.67%)
Mutual labels:  await
waspy
WASP framework for Python
Stars: ✭ 43 (+138.89%)
Mutual labels:  asyncio
of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (-27.78%)
Mutual labels:  await
duckpy
A simple Python library for searching on DuckDuckGo.
Stars: ✭ 20 (+11.11%)
Mutual labels:  asyncio
aioredis-cluster
Redis Cluster support extension for aioredis
Stars: ✭ 21 (+16.67%)
Mutual labels:  asyncio
spinach
Modern Redis task queue for Python 3
Stars: ✭ 46 (+155.56%)
Mutual labels:  asyncio
pydf
PDF generation in python using wkhtmltopdf for heroku and docker
Stars: ✭ 68 (+277.78%)
Mutual labels:  asyncio
pyaiot
A set of Python services to interact and transport data from IoT devices
Stars: ✭ 29 (+61.11%)
Mutual labels:  asyncio
py3tftp
An asynchronous TFTP server in pure Python 3.5
Stars: ✭ 39 (+116.67%)
Mutual labels:  asyncio
python3-concurrency
Python3爬虫系列的理论验证,首先研究I/O模型,分别用Python实现了blocking I/O、nonblocking I/O、I/O multiplexing各模型下的TCP服务端和客户端。然后,研究同步I/O操作(依序下载、多进程并发、多线程并发)和异步I/O(asyncio)之间的效率差别
Stars: ✭ 49 (+172.22%)
Mutual labels:  asyncio
showdown-battle-bot
Socket Battle Bot for Pokemon Showdown (http://pokemonshowdown.com/)
Stars: ✭ 19 (+5.56%)
Mutual labels:  asyncio
python-logi-circle
Python 3.6+ API for Logi Circle cameras
Stars: ✭ 23 (+27.78%)
Mutual labels:  asyncio
async armor
Graceful drop-in replacement for asyncio.shield
Stars: ✭ 15 (-16.67%)
Mutual labels:  asyncio
sleepover
💤 Sleep, snooze & step methods
Stars: ✭ 13 (-27.78%)
Mutual labels:  await
tomodachi
💻 Microservice library / framework using Python's asyncio event loop with full support for HTTP + WebSockets, AWS SNS+SQS, RabbitMQ / AMQP, middleware, etc. Extendable for GraphQL, protobuf, gRPC, among other technologies.
Stars: ✭ 170 (+844.44%)
Mutual labels:  asyncio
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (+11.11%)
Mutual labels:  await

https://cdn.at7h.com/img/helo.png

helo

🌎 [English] ∙ [简体中文]

https://travis-ci.org/at7h/helo.svg?branch=master https://coveralls.io/repos/github/at7h/helo/badge.svg?branch=master https://app.codacy.com/project/badge/Grade/c68578653eb546488fadddd95f19939c PyPI - Python Version

Helo is a simple and small low-level asynchronous ORM using Python asyncio. It is very intuitive and easy to use.

Helo can help you easily build expressive common SQL statements in your asynchronous applications. You only need to use friendly object-oriented APIs to manipulate data without caring about the details of SQL statement writing and data processing.

  • Requires: Python 3.7+
  • Only supports MySQL now, and the version is 5.7+
  • Integration with web framework:
  • Not supports table relationship now

Installation

$ pip install helo

See the installation wiki page for more options.

Quickstart

See the wiki page for more information and quickstart documentation.

Basic Examples

First, you should to import helo and instantiate a global variable with helo.G

import helo

db = helo.G()

Defining models is simple:

class Author(helo.Model):
    id = helo.BigAuto()
    name = helo.VarChar(length=45, null=False)
    email = helo.Email(default='')
    password = helo.VarChar(length=100, null=False)
    create_at = helo.Timestamp(default=helo.ON_CREATE)


class Post(helo.Model):
    id = helo.Auto()
    title = helo.VarChar(length=100)
    author = helo.Int(default=0)
    content = helo.Text(encoding=helo.ENCODING.UTF8MB4)
    create_at = helo.Timestamp(default=helo.ON_CREATE)
    update_at = helo.Timestamp(default=helo.ON_UPDATE)

Show some basic examples:

import asyncio
import datetime


async def show_case():
    # Binding the database(creating a connection pool)
    await db.bind('mysql://user:password@host:port/db')
    # Creating tables
    await db.create_tables([Author, Post])

    # Inserting few rows:

    author = Author(name='at7h', password='1111')
    author_id = await author.save()
    print(author_id)  # 1

    authors = await Author.get(author_id)
    print(author.id, author.name)  # 1, at7h

    await Author.update(email='[email protected]').where(Author.id == author_id).do()

    ret = await Author.insert(name='pope', password='2222').do()
    posts = [
        {'title': 'Python', 'author': 1},
        {'title': 'Golang', 'author': 2},
    ]
    ret = await Post.minsert(posts).do()
    print(ret)  # (2, 1)

    # Supports expressive and composable queries:

    count = await Author.select().count()
    print(count) # 2

    # Last gmail author
    author = await Author.select().where(
        Author.email.endswith('gmail.com')
    ).order_by(
        Author.create_at.desc()
    ).first()
    print(author) # [<Author object at 1>]

    # Using `helo.adict`
    authors = await Author.select(
        Author.id, Author.name
    ).where(
        Author.id < 2
    ).all(wrap=False)
    print(author)  # [{'id': 1, 'name': 'at7h'}]

    # Paginate get authors who wrote Python posts this year
    authors = await Author.select().where(
        Author.id.in_(
            Post.select(Post.author).where(
                Post.update_at > datetime.datetime(2019, 1, 1),
                Post.title.contains('Python')
            ).order_by(
                Post.update_at.desc()
            )
        )
    ).paginate(1, 10)
    print(authors) # [<Author object at 1>]

    # How many posts each author wrote?
    author_posts = await Author.select(
        Author.name, helo.F.COUNT(helo.SQL('1')).as_('posts')
    ).join(
        Post, helo.JOINTYPE.LEFT, on=(Author.id == Post.author)
    ).group_by(
        Author.name
    ).rows(100)

asyncio.run(show_case())

With Quart

If you're using quart , a minimum application example is:

import quart
import helo

app = quart.Quart(__name__)
app.config["HELO_DATABASE_URL"] = "mysql://user:password@host:port/db"

db = helo.G(app)


@app.route('/api/authors')
async def authors():
    await Author.insert(
        name='at7h', email='[email protected]', password='xxxx'
    ).do()
    author_list = await Author.select().all(False)
    return quart.jsonify(author_list)


app.run()

Run it:

$ curl http://127.0.0.1:5000/api/authors
[{"email":"[email protected]","id":1,"name":"at7h","password":"xxxx"}]

👉 See more examples

Contributing 👏

I hope those who are interested can join in and work together.

Any kind of contribution is expected: report a bug 🐞, give a advice or create a pull request 🙋‍♂️

Thanks 🤝

  • Helo used aiomysql and was inspired by peewee in programming. Thank you very much for both!
  • Please feel free to ⭐️ this repository if this project helped you 😉 !
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].