Skip to main content

c2w

The c2w utility converts a CLI program to a Web service.

Installation

% pip install c2w

Getting Started

We convert kramdown to a web service to get an online Markdown renderer.

% c2w --mime text/html kramdown

c2w is serving on 127.0.0.1:8000 now.

% curl http://localhost:8000 -X POST --data-binary @- << __EOF__
heredoc> # TITLE
heredoc>
heredoc> This is **strong**.
heredoc> __EOF__

We could get the following.

<h1 id="title">TITLE</h1>

<p>This is <strong>strong</strong>.</p>

c2w handles both GET and POST requests and treats them as the same with the following rules.

  • The query string will be split by &, decoded and sent to kramdown as arguments.

  • The request body will be sent to the stdin of kramdown and the stdout of kramdown will be sent to the browser.

kramdown can translate Mardown to LaTex with the option -o latex. If we want to get the LaTex output, we could put -o&latex in the query string.

% curl 'http://localhost:8000?-o&latex' --data-binary @- << __EOF__
heredoc> # TITLE
heredoc>
heredoc> This is **strong**.
heredoc> __EOF__

We got the following.

\section{TITLE}\hypertarget{title}{}\label{title}

This is \textbf{strong}.

Serving as a CGI program with an HTTP Server

The HTTP server provided by c2w is not mature enough and not recommended to use in a production environment. You may want to use Apache HTTPd or Nginx. To achieve this you can run c2w in CGI mode.

Create a simple Shell script named netmark.

#!/bin/bash

c2w --cgi --mime text/html kramdown

Give it the execution permission and put it in the cgi-bin directory of your HTTP server.

Detailed Usage

Run c2w --help.

Why I Wrote It

c2w: Convert Any CLI Program to a Web Service

Release files for c2w 0.0.1

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

Built distribution (wheel)

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

Release files / c2w-0.0.1-py3-none-any.whl

Download URL c2w-0.0.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69e2203556b140fc02a1c0ab70af75b458b30c9f16e30c4c5c8f72ea560b2ede
BLAKE2b-256 checksum
How to use checksums
e36bc4b78fb26a36b87ec0205b535bcb56d5265a5bae3e227aa36974c676ff84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.10

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

0.0.0

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