python313-sys 3.13.15

Raw Rust bindings for CPython 3.13.15 C API
docs.rs failed to build python313-sys-3.13.15
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

python313-sys

Raw Rust bindings for the CPython 3.13.15 C API.

This crate provides low-level FFI access to CPython internals and is intended to be used as a foundation layer for building safe and idiomatic Rust abstractions over Python.

Features

  • ✅ CPython 3.13.15 C API bindings
  • ✅ Generated automatically using bindgen
  • ✅ Native linking against Python 3.13
  • ✅ Access to raw PyObject APIs
  • ✅ Compatible with Rust 2024 edition

Requirements

  • Python 3.13.15
  • C compiler toolchain
  • LLVM/Clang (required by bindgen)

The crate automatically searches for Python installation using pyconfig.

Installation

Add this to your Cargo.toml:

[dependencies]

python313-sys = "3.13.15"

Usage

use python313_sys::*;

fn main() {
    unsafe {
        Py_Initialize();

        let version = Py_GetVersion();

        println!("Python version: {:?}", version);

        Py_Finalize();
    }
}

About

python313-sys is a low-level binding layer.

It intentionally does not provide:

  • safe Rust wrappers
  • automatic reference counting
  • ownership management
  • Rust-friendly error handling

The API mirrors CPython's C interface as closely as possible.

Higher-level abstractions should be built on top of this crate.

Example:

your_application
        |
        v
 safe Python wrapper
        |
        v
 python313-sys
        |
        v
 CPython C API

Building

During compilation, build.rs:

  1. Finds Python 3.13.15 installation
  2. Locates Python headers and libraries
  3. Runs bindgen
  4. Generates Rust FFI bindings
  5. Links against python313

Versioning

The crate version follows the supported CPython version:

python313-sys 3.13.15
        |
        +-- CPython 3.13.15

Only this Python version is supported.

Safety

This crate exposes unsafe CPython APIs.

Users must follow CPython's reference counting rules:

unsafe {
    Py_INCREF(obj);
    Py_DECREF(obj);
}

Incorrect usage may cause memory leaks, use-after-free, or interpreter crashes.

License

MIT License