Convert Figma logo to code with AI

cztomczak logocefpython

Python bindings for the Chromium Embedded Framework (CEF)

3,063
472
3,063
219

Top Related Projects

3,220

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.

113,668

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

83,441

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

12,580

Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).

24,924

Create beautiful applications using Go

Portable and lightweight cross-platform desktop application development framework

Quick Overview

CEFPython is a Python binding for the Chromium Embedded Framework (CEF). It allows developers to create desktop applications with web-based user interfaces using Python and web technologies like HTML, CSS, and JavaScript. CEFPython provides a way to embed Chromium-based browsers in Python applications, enabling the creation of rich, cross-platform GUI applications.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux)
  • Combines the power of Python with modern web technologies
  • Access to Chromium's advanced features and performance
  • Active development and community support

Cons

  • Large binary size due to Chromium dependencies
  • Steeper learning curve compared to traditional Python GUI libraries
  • Potential performance overhead for simple applications
  • Limited mobile platform support

Code Examples

  1. Creating a basic browser window:
from cefpython3 import cefpython as cef
import sys

def main():
    cef.Initialize()
    browser = cef.CreateBrowserSync(url="https://www.google.com",
                                    window_title="CEF Python Example")
    cef.MessageLoop()
    cef.Quit()

if __name__ == '__main__':
    main()
  1. Executing JavaScript in the browser:
from cefpython3 import cefpython as cef

def js_callback(result):
    print(f"JavaScript result: {result}")

browser.ExecuteJavascript("1+1", js_callback=js_callback)
  1. Handling browser events:
from cefpython3 import cefpython as cef

class ClientHandler:
    def OnLoadingStateChange(self, browser, is_loading, **_):
        if not is_loading:
            print("Page has finished loading")

client_handler = ClientHandler()
browser.SetClientHandler(client_handler)

Getting Started

To get started with CEFPython:

  1. Install CEFPython using pip:

    pip install cefpython3
    
  2. Create a new Python file (e.g., browser.py) and add the following code:

    from cefpython3 import cefpython as cef
    import sys
    
    def main():
        cef.Initialize()
        browser = cef.CreateBrowserSync(url="https://www.example.com",
                                        window_title="My First CEF Browser")
        cef.MessageLoop()
        cef.Quit()
    
    if __name__ == '__main__':
        main()
    
  3. Run the script:

    python browser.py
    

This will create a basic browser window displaying the specified URL. From here, you can explore more advanced features and customizations provided by CEFPython.

Competitor Comparisons

3,220

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.

Pros of CEF

  • Native C/C++ implementation, offering better performance and lower-level control
  • More comprehensive API with direct access to Chromium features
  • Wider platform support, including mobile and embedded systems

Cons of CEF

  • Steeper learning curve due to C/C++ complexity
  • Requires more manual memory management and resource handling
  • Larger binary size and more complex build process

Code Comparison

CEF (C++):

#include <cef_app.h>
#include <cef_client.h>

class SimpleHandler : public CefClient {
  // Implement necessary methods
};

int main(int argc, char* argv[]) {
  CefMainArgs main_args(argc, argv);
  CefSettings settings;
  CefInitialize(main_args, settings, nullptr, nullptr);
  CefRunMessageLoop();
  CefShutdown();
  return 0;
}

CEFPython (Python):

from cefpython3 import cefpython as cef
import sys

sys.excepthook = cef.ExceptHook
cef.Initialize()
cef.CreateBrowserSync(url="https://www.example.com")
cef.MessageLoop()
cef.Shutdown()

CEF provides a lower-level API with more control but requires more boilerplate code. CEFPython offers a simpler, Python-friendly interface at the cost of some flexibility and performance. CEF is better suited for large-scale applications requiring deep integration, while CEFPython excels in rapid prototyping and smaller projects where ease of use is prioritized.

113,668

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

Pros of Electron

  • Larger community and ecosystem, with more resources and third-party packages
  • Cross-platform development for desktop applications using web technologies
  • Built-in automatic updates and crash reporting features

Cons of Electron

  • Larger application size due to bundling Chromium and Node.js
  • Higher memory usage compared to native applications
  • Potential security concerns due to the broad access granted to web content

Code Comparison

CEFPython:

from cefpython3 import cefpython as cef
sys.excepthook = cef.ExceptHook
cef.Initialize()
browser = cef.CreateBrowserSync(url="https://www.example.com")
cef.MessageLoop()
cef.Shutdown()

Electron:

const { app, BrowserWindow } = require('electron')
function createWindow () {
  const win = new BrowserWindow({ width: 800, height: 600 })
  win.loadURL('https://www.example.com')
}
app.whenReady().then(createWindow)

CEFPython provides Python bindings for the Chromium Embedded Framework, allowing developers to embed Chromium-based browsers in Python applications. It offers a lightweight solution for creating desktop applications with web technologies, but has a smaller community compared to Electron.

Electron, on the other hand, uses Node.js and Chromium to create cross-platform desktop applications with JavaScript, HTML, and CSS. It has a larger ecosystem and more extensive documentation, but comes with increased resource usage and larger application sizes.

83,441

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

Pros of Tauri

  • Smaller application size due to using native OS webviews
  • Better performance and resource usage
  • Cross-platform support for desktop and mobile

Cons of Tauri

  • Less control over the rendering engine
  • Potential inconsistencies across different OS webviews
  • Steeper learning curve for developers new to Rust

Code Comparison

Tauri (Rust):

#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}!", name)
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

CEFPython (Python):

from cefpython3 import cefpython as cef
import sys

def main():
    sys.excepthook = cef.ExceptHook
    cef.Initialize()
    browser = cef.CreateBrowserSync(url="https://www.google.com/")
    cef.MessageLoop()
    cef.Shutdown()

if __name__ == '__main__':
    main()

Both frameworks allow for creating desktop applications with web technologies, but Tauri uses Rust and native webviews, while CEFPython uses Python and the Chromium Embedded Framework. Tauri offers better performance and smaller app sizes, while CEFPython provides more control over the rendering engine and may be easier for Python developers to adopt.

12,580

Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).

Pros of webview

  • Lightweight and easy to use, with a simple API
  • Cross-platform support (Windows, macOS, Linux) with native controls
  • Smaller binary size and lower memory footprint

Cons of webview

  • Limited JavaScript integration compared to CEF
  • Fewer customization options for the browser engine
  • Less comprehensive documentation and community support

Code Comparison

webview:

import webview

def on_closed():
    print("Window closed")

webview.create_window("Hello World", "https://example.com")
webview.start(on_closed)

cefpython:

from cefpython3 import cefpython as cef
import sys

sys.excepthook = cef.ExceptHook
cef.Initialize()
browser = cef.CreateBrowserSync(url="https://example.com",
                                window_title="Hello World")
cef.MessageLoop()
cef.Shutdown()

The webview code is more concise and straightforward, while cefpython offers more control and customization options. webview is ideal for simple applications that need to display web content, while cefpython is better suited for complex applications requiring advanced browser features and extensive JavaScript integration.

24,924

Create beautiful applications using Go

Pros of Wails

  • Uses native OS APIs, resulting in smaller, faster applications
  • Supports multiple programming languages (Go, JavaScript, TypeScript)
  • Easier to integrate with existing Go projects

Cons of Wails

  • Less mature and smaller community compared to CEFPython
  • Limited to desktop applications, while CEFPython can be used for both desktop and web-based projects
  • May require more custom development for complex UI scenarios

Code Comparison

CEFPython (Python):

from cefpython3 import cefpython as cef
import sys

sys.excepthook = cef.ExceptHook
cef.Initialize()
browser = cef.CreateBrowserSync(url="https://www.example.com")
cef.MessageLoop()
cef.Shutdown()

Wails (Go):

package main

import (
    "github.com/wailsapp/wails"
)

func main() {
    app := wails.CreateApp(&wails.AppConfig{
        Width:  1024,
        Height: 768,
        Title:  "My Wails App",
    })
    app.Run()
}

Both CEFPython and Wails offer solutions for creating desktop applications with web technologies, but they differ in their approach and target languages. CEFPython provides a Python binding for the Chromium Embedded Framework, while Wails focuses on creating native applications using Go and web technologies. The choice between them depends on the specific project requirements, target platform, and developer preferences.

Portable and lightweight cross-platform desktop application development framework

Pros of Neutralinojs

  • Lightweight and cross-platform, with a smaller footprint than CEF-based solutions
  • Uses native OS APIs, resulting in faster performance and lower resource usage
  • Simpler setup and development process, especially for web developers

Cons of Neutralinojs

  • Limited access to native APIs compared to CEF-based solutions
  • Smaller ecosystem and community support
  • May require additional work for complex native integrations

Code Comparison

Neutralinojs:

Neutralino.os.showMessageBox('Hello', 'Welcome to Neutralinojs!');

CEFPython:

from cefpython3 import cefpython as cef
cef.Initialize()
browser = cef.CreateBrowserSync(url="file:///index.html")
cef.MessageLoop()

Neutralinojs focuses on simplicity and lightweight development, making it easier for web developers to create desktop applications. CEFPython, being based on the Chromium Embedded Framework, offers more extensive native capabilities and browser features but comes with a larger footprint and more complex setup. The choice between the two depends on the specific requirements of your project, such as the need for advanced browser features or a lighter, more streamlined development process.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CEF Python

Table of contents:

Introduction

CEF Python is an open source project founded by Czarek Tomczak in 2012 to provide Python bindings for the Chromium Embedded Framework (CEF). The Chromium project focuses mainly on Google Chrome application development while CEF focuses on facilitating embedded browser use cases in third-party applications. Lots of applications use CEF control, there are more than 100 million CEF instances installed around the world. There are numerous use cases for CEF:

  1. Use it as a modern HTML5 based rendering engine that can act as a replacement for classic desktop GUI frameworks. Think of it as Electron for Python.
  2. Embed a web browser widget in a classic Qt / GTK / wxPython desktop application
  3. Render web content off-screen in applications that use custom drawing frameworks
  4. Use it for automated testing of web applications with more advanced capabilities than Selenium web browser automation due to CEF low level programming APIs
  5. Use it for web scraping, as a web crawler or other kind of internet bots

CEF Python also provides examples of embedding CEF for many Python GUI frameworks such as PyQt, wxPython, PyGTK, PyGObject, Tkinter, Kivy, Panda3D, PyGame, PyOpenGL, PyWin32, PySide and PySDL2.

Latest releases sponsored by

Thank you to Fivestars for sponsoring the v66.1 release with Python 3.8 / 3.9 support. Fivestars helps local communities thrive by empowering small businesses with cutting edge marketing technology. Please visit their website: Fivestars.com

Thank you to Lampix for sponsoring the v66 release. Lampix is the first hardware and software solution that turns any surface into a smart, augmented reality or interactive surface. Please visit their website: Lampix.com

Thanks to all sponsors

Install

You can install pypi/cefpython3 package using pip tool. On Linux pip 8.1+ is required. You can also download packages for offline installation available on the GitHub Releases pages. Command to install with pip:

pip install cefpython3==66.0

Tutorial

See the Tutorial.md document.

Examples

See the README-examples.md and README-snippets.md documents.

Support

Releases

Information on planned new and current releases, supported platforms, python versions, architectures and requirements. If you want to support old operating systems then choose the v31 release.

Next release

  • To see planned new features or bugs to be fixed in the near future in one of next releases, see the next release label in the tracker
  • To see planned new features or bugs to be fixed in further future, see the next release 2 label in the tracker

Latest release

OSPy2Py332bit64bitRequirements
Windows2.73.4 / 3.5 / 3.6 / 3.7 / 3.8 / 3.9YesYesWindows 7+ (Note that Python 3.9 supports Windows 8.1+)
Linux2.73.4 / 3.5 / 3.6 / 3.7YesYesDebian 8+, Ubuntu 14.04+,
Fedora 24+, openSUSE 13.3+
Mac2.73.4 / 3.5 / 3.6 / 3.7NoYesMacOS 10.9+

These platforms are not supported yet:

v49 release (WinXP/Vista)

OSPy2Py332bit64bitRequirements
Windows2.73.4YesYesWindows XP+
  • Install with command: pip --no-cache-dir install cefpython3==49.0.
    • Please note that if you were previously installing cefpython3 package it is required to use the --no-cache-dir flag, otherwise pip will end up with error message No matching distribution found for cefpython3==49.0. This happens because 49.0 release occured after 57.0 and 66.0 releases.
  • Downloads are available on GitHub Releases tagged v49.0.
  • See Migration guide document for changes in this release
  • Documentation is available in the docs/ directory in the cefpython49-winxp branch
  • API reference is available in the api/ directory in the cefpython49-winxp branch

v31 release (old systems)

OSPy2Py332bit64bitRequirements
Windows2.7NoYesYesWindows XP+
Linux2.7NoYesYesDebian 7+ / Ubuntu 12.04+
Mac2.7NoYesYesMacOS 10.7+

Additional information for v31.2 release:

  • On Windows/Mac you can install with command: pip install cefpython3==31.2
  • Downloads are available on the GitHub Releases page tagged v31.2.
  • API reference is available in revision 169a1b2
  • Other documentation can be downloaded by cloning the cefpython.wiki repository: git clone git@github.com:cztomczak/cefpython.wiki.git

Support development

If you would like to support general CEF Python development efforts by making a donation then please click the Paypal Donate button below. If you would like to see a specific feature implemented then you can make a comment about that when making a donation and that will give it a higher priority.



Thanks to all

  • [2021] Thank you to Fivestars for sponsoring the v66.1 release with Python 3.8 / 3.9 support
  • [2018] Thanks to Fivestars for sponsoring the v49 release for legacy systems (WinXP/Vista)
  • [2018] Many thanks to Lampix for sponsoring the v66 release for all platforms
  • [2017] Many thanks to HighSide Inc. for sponsoring the v55/v56 releases for all platforms
  • [2016-2018] Thanks to JetBrains for providing an Open Source license for PyCharm
  • [2014] Thanks to Adam Duston for donating a Macbook to aid the development of Mac port
  • [2013-2015] Lots of thanks goes to Cyan Inc. for sponsoring this project for a long time, making CEF Python 3 mature
  • [2013] Thanks to Rentouch GmbH for sponsoring the development of the off-screen rendering support
  • [2013] Thanks to Thomas Wusatiuk for sponsoring the development of the web response reading features
  • [2012-2018] Thanks to those who have made a Paypal donation: Rentouch GmbH, Walter Purvis, Rokas Stupuras, Alex Rattray, Greg Kacy, Paul Korzhyk, Tomasz Tomanek.
  • [2012-2017] Thanks to those who have donated their time through code contributions, they are listed in the Authors file

Seeking new sponsors

CEF Python is seeking companies to sponsor further development of the project. There are many proposals for new features submitted in the issue tracker. Most notable are:

  • Monthly releases with latest Chromium
  • An automated build system similar to upstream CEF Spotify Automated Builds
  • ARM and Android support
  • Multi-threaded support for increased performance
  • Proprietary codecs support in build tools: H264, H265,AC3, EAC3, MPEG-4
  • More CEF API exposed, only about 50% is exposed so far
  • Hundreds of new settings and Chromium preferences not yet exposed
  • Easier integration with popular GUI toolkits in just a few lines of code and support for more third party GUI frameworks
  • More examples of implementing various advanced features and more snippets as well

If your company would like to sponsor CEF Python development efforts then please contact Czarek. Long term sponsorships are welcome and Czarek is open to ideas about the project. He would love to spend more time on developing this project, but he can't afford doing so in his free time. Currently there is no company supporting this project actively on a daily basis.

Other READMEs

Quick links

Docs

API categories

Modules

Settings

Classes and objects

Client handlers (interfaces)

Other interfaces

API index