Skip to main content

Parsely

https://travis-ci.org/narusemotoki/parsely.svg?branch=master

Parsely is a framework for enqueuing messages via HTTP request for celery.

CHANGELOG

Example

tasks.py:

from typing import Dict

import parsely


app = parsely.Parsely('example', 'redis://localhost:6379/0')


def two_times(text: str) -> Dict[str, str]:
    return {
        'text': text * 2
    }


@app.task(two_times)
def echo(text: str) -> None:
    print(text)


worker = p.celery
producer = p.make_producer()

two_times works as pre processor. It works before enqueing. It means it can return BadRequest to your client. Parsely validate message with typehint. Also you can have extra validation and any other process here.

You can run tasks.py as Celery worker: celery -A tasks worker --loglevel=info

Also it runs as WSGI application. This is an example run it with uWSGI uwsgi --http :8080 --wsgi-file tasks.py --callable producer --enable-threads --thunder-lock --master

Send Test Message!

curl -X POST -d '{"message":{"text": "Hello"}}' http://localhost:8080/example/echo

  1. producer receives your request

  2. producer validates your message having text and the type is str or not. text`(str) is from typehint of two_times

  3. producer validates two_times returned value having text and the type is str or not. text`(str) is from typehint of echo

  4. producer put message {"message":{"text":"HelloHello"}} into queue.

  5. curl receives response.

  6. Celery calls echo

Extra

Preprocessor

preprocessor is optional. if you don’t need it, you can:

@app.task()
def echo(text: str) -> None:
    print(text)

Also you can give multiple preprocessor:

@app.task(two_times, two_times)
def echo(text: str) -> None:
    print(text)

logging

Parsely uses logger witch named “parsely”, so you can set log level like:

import logging


parsely_logger = logging.getLogger('parsely')
parsely_logger.setLevel(logging.DEBUG)

Metadata

Release files for parsely 0.7.0

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

Source distribution (sdist)

Source distribution for parsely 0.7.0
File Size Uploaded Provenance Actions
parsely-0.7.0.tar.gz 10.9 kB Without provenance Details for parsely-0.7.0.tar.gz

Release files / parsely-0.7.0.tar.gz

Download URL parsely-0.7.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
557576d116e320fb68b576135746b4c95b02755a835fd8fcd4dbc57f112b5cbf
BLAKE2b-256 checksum
How to use checksums
61d3b0bb9d6c98fcf300d825967796171ffdc891b3b11ed8ce72a659c9ae3431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for parsely 0.7.0

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.

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