Py2Web is an utility for people who create webpages. It allows embedding chess problems viewer into the webpages in a way similar to that in which the PGN viewers work. The difference is that Py2Web supports many features that PGN viewers don't, e.g.: idling (set-play, threat, series-movers), twins, fairy pieces, fairy effects (rebirth, piece color change etc).


Example #3 problem by V. Chepizhny >>153689. Feel free to test your problems.

Starting position
in popeye 'Pieces' clause format:

in popeye output format with optional {comments}:

(Protip: you can copy and paste both fields from olive)
(Protip2: click right/left parts of the diagram to play the solution forward/backward)

More examples

Something more complicated. View this page source to check the syntax (it is 100% popeye output format).

Twins, promotions, rebirth and promotion as result of the rebirth

C. J. Feather
Fairings (28/5), 2012-11
white Pb3 Bg1 Ra4 Ka2 black Pb6h2a3g7b5 Sb2f5 Bc5d7 Kd4 Re4
h#2 CouscousCirce + Isardam
b) bPg7→g4
a) 1.h2*g1=Q[+wBd8] Ra4-c4 2.Bc5-f8 Bd8*b6[+bPc1=Q] # b) bPg7-->g4 1.Sb2*a4[+wRg8] Bg1-e3 2.Re4-e7 Rg8*g4[+bPh1=S] #

Fairy piece (nightrider), T&M notation, color change, kobul king

You can temporary hide solution from solvers, it is stil working.
P. Tritten & D. Turevski
Julia's fairies, 2013/I, 7th Prize
ded. to D. Kostadinov
black Pg7f6b6g3g5a5a7 Kc2 Rc4 Bh1 Nb5
AntiAndernach + KoBulKings +
Show solution

Long series-helpmate with rook-locust and PWC

Note how empty comments are used to add linebreaks. Also you can add any static HTML in comments. Diamond-shaped rook-locust illustrates the usage of the glyphs attribute (see "Usage" below, here glyphs='{"lr":"d"}').
C. J. Feather
Fairings (22/11), 2012-02
white Pd2 Kd5 lrg5 black Kc1
PWC, Rook-Locust g5
1.Kc1-d1 2.Kd1-e2 3.Ke2*d2[+wPe2] 4.Kd2-e3 5.Ke3*e2[+wPe3] { } 6.Ke2-f3 7.Kf3*e3[+wPf3] 8.Ke3-f4 9.Kf4*g5[+wLRf4] 10.Kg5-h4 { } 11.Kh4-g3 12.Kg3*f4[+wLRg3] 13.Kf4-e3 14.Ke3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-b7[Ib8] Gc7-c5[Ib6] { } 5.Kg4-g3[Ib5] Gb2-b5[Ib8] 6.Gc6-c4[Ib6] Gb4-b6[Ib8] 7.Kg3-f2[Ia7] Gb5-d5[Ic7] 8.Kf2-f1[Ic6] Gd5-b5[Ia6] { } 9.Gc4-e2[Ic4] Gc5-a7[Ia6] #


This is what you add to the <head> part of your document:

<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript" src="py2web.js"></script>
<link href="py2web.css" rel="stylesheet" type="text/css" />
Feel free to edit CSS to change the look.

This is what you add to the <body> part of your document where you want the diagram and solution widgets to be displayed:

<div class="p2w-diagram" id="myUniqueId" glyphs='{"g":"q1","du":"p2"}'>
	[Starting position (in popeye 'Pieces' clause format)]
<div class="p2w-solution" target="myUniqueId" full-move="wb" start-node="first">
	[Solution (in popeye output format)]

.p2w-diagram attributes:

.p2w-solution attributes:

This is where you download py2web files and jQuery:
Version history:


Py2Web defines one useful JS method that you can call on your pages if you need more dynamics and flexibility.


It has no return value. It iterates through all children of the selector that have class .p2w-solution and replaces their content with the solution widget while also replacing the content of the corresponding .p2w-diagram elements with the diagram widget.
As you already may have guessed Py2Web calls


when the page has loaded. However, you can load problem content dynamically into some container later and then call


The live demo at the top of this page works in exactly this way. It dynamically creates .p2w-solution and .p2w-diagram elements based on values in the textboxes, nests them within '#demo' div and then calls Py2Web.init('#demo'). Here's the actual source code, jQuery-style:

$(document).ready(function() {
    $("button").click(function() {
                .attr('id', 'demo-board').html($("#py-pieces").val()))
                .attr('target', 'demo-board').html($("#py-output").val()))        

Error handling

Is minimal as of yet. Syntax and semantic errors (if any) are logged in the javascript console. If something isn't working - check console (Ctrl+Shift+J in Chrome and FF).

Under the hood

Py2Web is a free software with open source code. The parser part of the Py2Web is written in JS/CC which is a lexer/parser generator. You may need to have a general knowledge of what a compiler-compiler is.

Updated: 2014-06-25