<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" width="40px" /> CPython engine is under active development and might be unstable. If you want to use python for development, it is preferred to use IronPython. CPython should only be used when accessing C-based python packages (e.g. numpy, scipy) is necessary.

</aside>

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" width="40px" /> Take a look at the Create Your First Command for information about setting up your first extension. This article explains how to create a Cpython script in pyRevit. The rest is the same.

</aside>

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/63345d83-5adb-4543-a729-5f1d9c39d8b5/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/63345d83-5adb-4543-a729-5f1d9c39d8b5/ic_01_idea.png" width="40px" /> pyRevit uses the embedded CPython engine. This engine looks at the PYTHONPATH environment variable for search paths for modules. You can set this variable on your system and pyRevit CPython commands will also find the modules you have installed using python package managers e.g. pip or pipenv

</aside>

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ecd3949e-1570-49f5-8a8f-9dd6da1d6446/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ecd3949e-1570-49f5-8a8f-9dd6da1d6446/alert.png" width="40px" /> Revit is a 64-bit application. Please make sure that you are using the 64-bit version of CPython when creating CPython bundles for pyRevit.

</aside>

Writing The Script

pyRevit CPython scripts are almost identical to IronPython. The benefit is that you can import the CPython modules that are written in C language and therefore are not compatible with IronPython e.g. numpy and scipy

To create a CPython script, create a python script as described at Create Your First Command and start the first line with the CPython identifier

#! python3

The rest is business as usual.

#! python3
import numpy as np
import pandas as pd

from pyrevit import revit

print("\\n## numpy array:")
print(repr(np.arange(15).reshape(3, 5)))

df_dict = {'key 1': 1, 'key 2': 2, 'key 3': 3}
df = pd.DataFrame([df_dict])

print("\\n## pandas DataFrame:")
print_html(df.to_html().replace('\\n', ''))

for element in revit.get_selection():
    print(element)

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/663f6be5-40f9-4611-9f81-252f934825f3/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/663f6be5-40f9-4611-9f81-252f934825f3/ic_01_idea.png" width="40px" /> See Anatomy of CPython Scripts

</aside>