# Compiling a smart contract in Python

### Challenges:&#x20;

* Python requires an interpreter to execute
* CPython - the reference Python implementation is quite big (30MiB+) and hence not suitable for QVM environment due to cost

### Solution:

We already supply a simple compiler container which uses a compact interpreter. While it has partial trade-offs regarding some functionality compared to the full-blown CPython, for QVM smart contract world it is still acceptable, and **costs 100x less to deploy due to the size savings**!

Still, when compiling a Python contract one wants to reduce the resulting binary size to the bare minimum possible to save on deployment fees, since that metric is tied only to the size of the deployed binary. As a good rule of thumb is to always strip all removable metadata (e.g.: DWARF, symbol table and debug info).

The QVM compiler enables presets which help to achieve an extremely small static binary as a result.

### Compiling Pyhton smart contract to static binary with the QVM compiler

We already supply a simple compiler container which will perform the most optimized build of turning above sample contract to a static binary which can be run by QVM.

Since you saved the previous sample contract as `main.py` in your current directory, you can run the compiler like this:

```bash
docker run --rm -v $(pwd):/ws qanplatform/qvm-compiler-python
```

Afterwards you will end up with a statically linked linux ELF binary called “contract” in your current directory.

```bash
# checking output size of QVM compiler
ls -alh contract
-rwxr-xr-x  1 user  group    247K Jun 8 14:03 contract
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.qanplatform.com/developers/qvm-multi-language-smart-contracts/docs-for-supported-languages/python-smart-contract/compiling-a-smart-contract-in-python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
