Spyce
Encyclopedia
Spyce is technology similar to PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

 that can be used to embed Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

 code into webpages. Spyce is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

, distributed under a BSD-style licence, with some additional restrictions about documentation notices.

Common Spyce Embedding Methods

Since Python uses indentation to determine the beginning and end of a block, Spyce includes several ways to embed Python code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

. Shown below are the three most common ways. Spyce supports ASP
Active Server Pages
Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated Web pages. Initially released as an add-on to Internet Information Services via the Windows NT 4.0 Option Pack Active Server Pages (ASP), also known as Classic...

/JSP
JavaServer Pages
JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...

-style delimiter
Delimiter
A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values.Delimiters represent...

s (<% and %>) as well as double braces (" and ")

1. Python 'chunks' (multiple Python statements with traditional indentation
Indentation
An indentation may refer to:* A notch, or deep recesses; for instance in a coastline, or a carving in rock* The placement of text farther to the right to separate it from surrounding text....

):


It's \

from time import asctime, localtime
print asctime(localtime)

right now!


or


It's <%\

from time import asctime, localtime
print asctime(localtime)

%>
right now!


2. Individual statements within delimiters (indentation not required):

for x in xrange(3): {
Hello,
}

or

<% for x in xrange(3): { %>
Hello,
<% } %>

3. Expressions evaluation

I am = 5*3  years old.

or

I am <%= 5*3 %> years old.

The techniques above can be freely mixed and embedded in any HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 document.

Any legal Python code can be embedded and any Python module can be imported, which makes it especially suited for writing very robust applications (using exception handling
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....

 and unit test
Unit test
In computer programming, unit testing is a method by which individual units of source code are tested to determine if they are fit for use.A unit is the smallest testable part of an application. In procedural programming a unit could be an entire module but is more commonly an individual function...

ing single modules individually).

Features

Some other features include custom tags (ala JSP), spyce lambdas and active handlers (reminiscent of ASP).

Requirements

Spyce brings Python's standard library and the programming language itself to the web. The minimum requirement is a working Python installation (it ships with a standalone web server written in Python that can be used during development), although it can be used in conjunction with several web servers such as Apache and IIS in a variety of ways.

Configuration is done using Python modules that are imported by the web server during initialization, so all that is really required to get started with Spyce is basic knowledge of Python.

See also

  • mod python
    Mod python
    mod_python is an Apache HTTP Server module that integrates the Python programming language into the Apache server. It is intended to replace Common Gateway Interface as a method of executing Python scripts on a web server. The promised benefits are faster execution speed and maintaining data over...

  • Spyce Tips and Techniques

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK