Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Pypperoni/pypperoni
Pypperoni Python Compiler Source Code
https://github.com/Pypperoni/pypperoni
bytecode c compiler python python-bytecode python-compilers
Last synced: 12 days ago
JSON representation
Pypperoni Python Compiler Source Code
- Host: GitHub
- URL: https://github.com/Pypperoni/pypperoni
- Owner: Pypperoni
- License: mit
- Created: 2018-07-23T19:16:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T01:18:03.000Z (over 3 years ago)
- Last Synced: 2024-01-07T08:08:18.715Z (10 months ago)
- Topics: bytecode, c, compiler, python, python-bytecode, python-compilers
- Language: Python
- Homepage:
- Size: 113 KB
- Stars: 77
- Watchers: 17
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Pypperoni Compiler
Pypperoni is a free and open source Python compiler and bytecode preprocessor designed and maintained by the developers of [The Legend of Pirates Online](https://tlopo.com/), a fan-made recreation of Disney's Pirates of the Caribbean Online.
This is the main source code repository.
## Overview
Python, by design, is an interpreted programming language. This means that a Python program's source code is first compiled to a bytecode format and then interpreted at runtime. This can lead to certain security issues, such as bytecode dumping and injection.
Pypperoni's main objective is to eliminate the interpreter by preprocessing your bytecode and expanding it to Python C API calls at compile time.
## Getting Started
### Downloading Sample Projects
To best get a feel of how Pypperoni works, try downloading one of our many [sample projects](http://github.com/pypperoni/samples). To get started, please follow each project's included guide on how to set them up. These samples are a good example of how to properly structure your own Pypperoni project.## Why use Pypperoni?
Pypperoni was designed with security as a central focus. Our compiler provides you with the necessary tools to run a secure and high quality Python application.With the removal of the interpreter, it is practically impossible to inject Python code into your program and/or recover the original source code.
Additionally, by preprocessing the bytecode there may be a performance boost in your application.
## How does Pypperoni work?
When Pypperoni is ran, it will compile all of your Python application's source code (`*.py`) into Python bytecode (`*.pyc`). An example of Python bytecode is shown below:```
0 SETUP_LOOP 32 (to 34)
2 LOAD_NAME 0 (enumerate)
```Next, Pypperoni will read through the bytecode, interpreting the Python OP codes into the equivalent Python C API calls; this is what we call "preprocessing the bytecode." The following example is the output from preprocessing the above bytecode:
```c
label_0:
{
void* __addr;
GET_ADDRESS(__addr, label_34, 34);
PyFrame_BlockSetup(f, 120, __addr, STACK_LEVEL());
}
label_2:
{
x = __pypperoni_IMPL_load_name(f, __consts_main[0]); /* 'enumerate' */
if (x == NULL) {
f->f_lineno = 5;
goto error;
}
Py_INCREF(x);
PUSH(x);
}
```This C code is then compiled as a normal C application, and an executable is generated.
## Documentation
Pypperoni is still in its infancy. We will be writing and publishing documentation over time [here](http://pypperoni.github.io/).## Development
### Background
Pypperoni was developed initially as an in-house compiler for the free online game, The Legend of Pirates Online ("TLOPO"). TLOPO, which is almost entirely written in Python, had to come up with many creative solutions for security problems intrinsic to the Python programming language, such as Python injection.They recognized the numerous security and performance issues associated with running a production application written in Python, and thus sought out to reinvent the way we traditionally think about Python compilers. Pypperoni is the result of this vision.
Previously, TLOPO maintained their own custom and open source compiler named [Nirai](https://github.com/nirai-compiler). Unlike Pypperoni, Nirai was designed to be specifically used alongside the Panda3D game engine. Pypperoni is the successor to Nirai and is designed to be compatible with any application written in Python 2.7.
### Maintainers
- **[@loblao](https://github.com/loblao) Nacib Neme** is Pypperoni's lead architect and designer.
- **[@mfwass](https://github.com/mfwass) Michael Wass** is a maintainer of Pypperoni.## License
Pypperoni is licensed under the MIT License; you may not use it except in compliance with the License.You may obtain a copy of the License [here](LICENSE.txt).
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
## Contributors
We welcome any potential contributors! But before hacking away and sending off a bunch of new pull requests, please check out the current issues and pull requests. If you would like to add a new feature or fix a bug, please submit an issue describing the bug or feature. This way we can always make sure we're all on the same page.