from emmett import App, request, response
from emmett.orm import Database, Model, Field
from emmett.tools import service

class TimeTravel(Model):
    traveler = Field.string()
    returned = Field.bool(default=False)

app = App(__name__)
db = Database(app)
app.pipeline = [db.pipe]

async def completed_travels():
    page = request.query_params.page or 1
    travels = TimeTravel.where(
        lambda t: t.returned == True
    ).select(paginate=(page, 20))
    return {'travels': travels}
Write elegant code

Focus on your product

You should spend more time on your product rather than the underlying framework.

Emmett is the framework for inventors since is designed to simplify your development process, with a syntax made to be simple, easy to learn and understand.

Don't waste your time between routers and uncomfortable patterns: every time you write down a route for your application, everything is just clearly stated in front of your eyes.

Go asynchronous

Enjoy sockets

Emmett is designed on top of latest asyncio Python technology.

The whole request flow in Emmett is fully asynchronous, so you can easily take advantage of asynchronous and non-blocking code in your application flow.

Need to listen for latest time travels happening in your time? With Emmett you can handle websockets in a few lines, without bothering about handling the parallelism.

from emmett import websocket

async def time_travels():
    channel = await mypubsub.subscribe(
    await websocket.accept()

    while True:
        async for travel in channel.iter():
            await websocket.send(travel)
from emmett.orm import Model, has_many, belongs_to

class Passenger(Model):

class Position(Model):
        {'departures': 'TimeTravel.source'},
        {'arrivals': 'TimeTravel.destination'},
        {'travelers': 'TimeTravel.passenger'}

class TimeTravel(Model):
        {'source': 'Position'},
        {'destination': 'Position'}

Define your entities

Relations in a breeze

Writing models and relations in Emmett is fast and concise.

Defining the entities involved in your application shouldn't be a pain.
Emmet's ORM apis are designed to avoid you the hassle of writing cryptic code and to be perfectly readable even for databases amateurs.

Enjoy the elegance of your models and use your time to improve your product.

Count what matters

Aggregation made easy

Just forget underscore variables and raw sql strings.

Emmett comes with a powerful query interface that lets you aggregate your data using just the Python language.

Need to count events happening in the same location for a specific year? Emmett lets you do that in just some few elegant lines.

class Event(Model):
    location = Field.string()
    happens_at = Field.datetime()

events_count = Event.id.count()
    Event.happens_at.year() == 1955
    having=(events_count > 10))
{{ extend 'layout.html' }}

<div class="time-travels">
  {{ for idx, travel in enumerate(travels): }}
  {{ style_class = "gray" if idx % 2 else "light" }}
  <div class="travel {{ =style_class }}">
    <h2>{{ =travel.destination }}</h2>
  {{ pass }}

  {{ if not travels: }}
    <em>No time travels so far.</em>
  {{ pass }}
Design your success

Forget about templating syntax. Use Python

Emmett won't propose you a new templating language, with a different syntax and logic: you should not waste time on that.

The templating engine shipped with Emmett is indeed just pure Python code embedded in your templates, with some facilities added to the game.

Use the same language for both the back-end logic and the front-end one.

Ready to go?

The easies way to install Emmett is from PyPI, using pip:

> pip install emmett

Then you may want to:

Batteries included