Skip to main content
https://img.shields.io/pypi/v/Pyjoyment.png https://travis-ci.org/dex4er/Pyjoyment.png?branch=master https://readthedocs.org/projects/pyjoyment/badge/?version=latest

Pyjoyment

An asynchronous, event driver web framework for the Python programming language.

Pyjoyment provides own reactor which handles I/O and timer events in its own main event loop but it supports other loops, ie. libev, asyncio.

Pyjoyment uses intensively own event emmiter which should be familiar for Node.JS programmers.

It provides tool set for parsing and creating HTTP messages and HTML documents. It also supports WSGI interface.

Pyjoyment is compatible with Python 2.7+, Python 3.3+ and PyPy 2.4+. It doesn’t require any external libraries or compilers.

See http://www.pyjoyment.net/

Pyjoyment is based on Mojolicious: a next generation web framework for the Perl programming language.

Status

Early developement stage. Implemented already:

  • WSGI adapter

  • HTTP standalone async-io server

  • WebSockets client and server

  • HTTP user agent with TLS/SSL support

  • JSON pointers implementation based on RFC6901

  • Embedded files loader

  • HTML/XML DOM parser with CSS selectors

  • URL parser with container classes for URL, path and querystring

  • Non-blocking TCP client and server

  • Simple logging object

  • Synchronizer and sequentializer of multiple events

  • Main event loop which handle IO and timer events

  • Event emitter with subscriptions

  • Low level event reactor based on select(2) and poll(2)

  • Convenient functions and classed for unicode and byte strings and lists

  • Lazy properties for objects

  • Test units with API based on Perl’s Test::More and TAP protocol

Examples

Web scraping

import Pyjo.UserAgent
from Pyjo.String.Unicode import u

tx = Pyjo.UserAgent.new().get('https://html.spec.whatwg.org')
for n in tx.res.dom('#named-character-references-table tbody > tr').each():
    u(n.at('td > code').text + ' ' + n.children('td')[1].text).trim().say()

URL manipulation

import Pyjo.URL
from Pyjo.String.Unicode import u

# 'ssh+git://git@github.com/dex4er/Pyjoyment.git'
url = Pyjo.URL.new('https://github.com/dex4er/Pyjoyment')
print(url.set(scheme='ssh+git', userinfo='git', path=u(url.path) + '.git'))

# 'http://metacpan.org/search?q=Mojo::URL&size=20'
print(Pyjo.URL.new('http://metacpan.org/search')
      .set(query={'q': 'Mojo::URL', 'size': 20}))

Non-blocking TCP client/server

import Pyjo.IOLoop


# Listen on port 3000
@Pyjo.IOLoop.server(port=3000)
def server(loop, stream, cid):

    @stream.on
    def read(stream, chunk):
        # Process input chunk
        print("Server: {0}".format(chunk.decode('utf-8')))

        # Write response
        stream.write(b"HTTP/1.1 200 OK\x0d\x0a\x0d\x0a")

        # Disconnect client
        stream.close_gracefully()


# Connect to port 3000
@Pyjo.IOLoop.client(port=3000)
def client(loop, err, stream):

    @stream.on
    def read(stream, chunk):
        # Process input
        print("Client: {0}".format(chunk.decode('utf-8')))

    # Write request
    stream.write(b"GET / HTTP/1.1\x0d\x0a\x0d\x0a")


# Add a timer
@Pyjo.IOLoop.timer(3)
def timeouter(loop):
    print("Timeout")
    # Shutdown server
    loop.remove(server)


# Start event loop
Pyjo.IOLoop.start()

Standalone HTTP server serving embedded template file

# -*- coding: utf-8 -*-

import Pyjo.Server.Daemon
import Pyjo.URL

from Pyjo.Loader import embedded_file
from Pyjo.Util import b, u

import sys


opts = dict([['address', '0.0.0.0'], ['port', 3000]] + list(map(lambda a: a.split('='), sys.argv[1:])))
listen = str(Pyjo.URL.new(scheme='http', host=opts['address'], port=opts['port']))

daemon = Pyjo.Server.Daemon.new(listen=[listen])
daemon.unsubscribe('request')


# Embedded template file
DATA = u(r'''
@@ index.html.tpl
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Pyjoyment</title>
</head>
<body>
<h1>♥ Pyjoyment ♥</h1>
<h2>This page is served by Pyjoyment framework.</h2>
<p>{method} request for {path}</p>
</body>
</html>
''')


@daemon.on
def request(daemon, tx):
    # Request
    method = tx.req.method
    path = tx.req.url.path

    # Template
    template = embedded_file(sys.modules[__name__], 'index.html.tpl')

    # Response
    tx.res.code = 200
    tx.res.headers.content_type = 'text/html; charset=utf-8'
    tx.res.body = b(template.format(**locals()))

    # Resume transaction
    tx.resume()


daemon.run()

Metadata

Release files for Pyjoyment 0.0.1

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

Source distribution (sdist)

Source distribution for Pyjoyment 0.0.1
File Size Uploaded Provenance
Pyjoyment-0.0.1.tar.gz 127.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for Pyjoyment 0.0.1
File Interpreter ABI Platform
Pyjoyment-0.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 291.4 kB

Release files / Pyjoyment-0.0.1.tar.gz

Download URL Pyjoyment-0.0.1.tar.gz
Size 127.7 kB
Tags Source
SHA-256 checksum
How to use checksums
95439ec44979d839f46a80a54b6fe15899ad1c435166405a1aac0b12bdcee7f0
BLAKE2b-256 checksum
How to use checksums
2dd61ab9fca946665ed9482c52a80def86f72a330586e20433fc5114848f7515
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Pyjoyment-0.0.1-py2.py3-none-any.whl

Download URL Pyjoyment-0.0.1-py2.py3-none-any.whl
Size 163.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2cb11f7d77661348a00d8834456e68a7bcf4c5470c155a697e88096fc04915d5
BLAKE2b-256 checksum
How to use checksums
d28770ea3ef912637ae2370bfa58a4a6692d9e3c91258f862aea808546bce16b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for Pyjoyment 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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