--- id: cymem version: "2.0.13" license: MIT license_treatment: permissive maintenance: active --- # cymem — Manage calls to calloc/free through Cython License: permissive · Maintenance: active · Downloads: 21.4M/mo ## What it is and what it does cymem is a Cython library that wraps C's calloc/free functions in a Python-managed Pool object. Instead of manually tracking and freeing allocated memory in Cython code, you attach a Pool to your Cython class and call pool.alloc() for all memory allocations. When the Pool is garbage collected (along with its parent object), all tracked memory is automatically freed—eliminating manual deallocation code and the bugs that come with it. The library is designed for performance-critical Cython code that works with C-level structs and arrays. It supports custom allocators via WrapMalloc and WrapFree, and as of version 2.0.12, is thread-safe on CPython 3.13+ free-threaded builds. With no runtime dependencies and precompiled wheels for modern Python versions and architectures, it integrates cleanly into existing Cython projects. Use it for: - Building arrays of C structs in Cython without writing complex __dealloc__ methods. - Wrapping external C libraries that use private malloc/free functions via custom allocators. - Managing deeply nested C data structures where manual deallocation is error-prone. - Reducing memory-leak bugs in performance-critical Cython extensions. - Simplifying memory lifecycle in Cython classes that hold C-level pointers. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. cymem provides memory-management helpers for Cython that tie C-allocated memory to Python object lifecycles, automatically freeing memory when the object is garbage collected. Yes, if you write Cython code that allocates C memory. cymem eliminates a common source of bugs (manual deallocation) and is actively maintained with no known vulnerabilities. Install friction is medium due to Cython and compiler requirements, but that's inherent to Cython development, not cymem itself. Not relevant for pure-Python projects. ## Install pip install cymem uv add cymem poetry add cymem ## Installing cymem Before you install: Precompiled wheels available for Python 3.9–3.14 across macOS, Linux, Windows, and ARM platforms; medium install friction due to Cython dependency. Active maintenance with last commit 2026-03-27 and no known vulnerabilities. License in practice: MIT license (permissive) allows use in commercial and proprietary projects with minimal restrictions; attribution required. Quickstart: # Install pip install cymem # In a .pyx Cython file: from cymem.cymem cimport Pool cdef Pool mem = Pool() cdef int* data = mem.alloc(10, sizeof(int)) # Memory is automatically freed when Pool is garbage collected Requires Cython to be installed and a C compiler available; intended for use in .pyx files, not pure Python. Verify before relying: - Whether the package is actively used in production by major NLP/ML libraries beyond what can be inferred from download volume. - Performance overhead of the Pool wrapper compared to direct calloc/free calls. - Thread-safety guarantees for Python versions prior to 3.13 free-threaded builds. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: medium - Maintenance: active - Downloads: 21.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags cython memory management, cython calloc wrapper, automatic memory deallocation cython, cython pool allocator, manage c memory in cython, cython memory pool, prevent memory leaks cython, cython, memory-management, c-extension [View on SkillFed](https://skillfed.io/packages/cymem) · [View on PyPI](https://pypi.org/project/cymem/)