Convert Figma logo to code with AI

cztomczak logocefpython

Python bindings for the Chromium Embedded Framework (CEF)

3,139
475
3,139
221

Top Related Projects

3,680

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

116,011

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

88,583

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

12,816

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

26,445

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,680

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.

116,011

: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.

88,583

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,816

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.

26,445

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.

Install

Command to install with pip:

pip install cefpython3==66.1

Hosted at pypi/cefpython3. On Linux pip 8.1+ is required.

You can also download packages for offline installation available on the GitHub Releases pages.

Below is a table with supported platforms, python versions and architectures.

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+

Examples

Support

Support development

To support general CEF Python development efforts you can make a donation using PayPal button below:


Seeking sponsors

CEF Python is seeking companies to sponsor development of this project. Most important thing would be to have continuous monthly releases with updates to latest Chromium. There is also lots of cool features and new settings that would be nice to implement. We have not yet exposed all of upstream CEF APIs. If your company would like to sponsor CEF Python development efforts then please contact Czarek. There are no active sponsors at this moment.

Previous sponsors

API

Modules

Settings

Classes and objects

Client handlers (interfaces)

Other interfaces

API index