Example for how to package a Python library based on Cython.

Overview

Cython sample module

This project is an example of a module that can be built using Cython. It is an upgrade from a similar model developed by Arin Khare.

Structure

The structure of this project is as follows:

.
├── cython_example
│   ├── dataset
│   ├── hello.pyx
│   └── matrix
|       ├── matrix.pyx
|       ├── norm1.pyx
|       └── trace.pyx
├── MANIFEST.in
├── pyproject.toml
├── README.md
├── test
│   └── test.py
└── setup.py

Let me describe the individual components:

  • *.pyx are files that will be compiled to native code from Cython/Python sources.
  • dataset is an example of a file that will be installed raw.
  • hello.pxd is a Cython file that will be compiled to a module with the path cython_example.hello
  • matrix.pyx is a Cython file that joins two other files, norm1.pyx and trace.pyx, which will be joined under the same submodule, cython_example.matrix
  • MANIFEST.in enumerates additional files that need to be installed in the package.
  • pyproject.toml lists packages required to build this module (Cython, to start with), but which are not required for execution.
  • README.md is this long description.
  • setup.py is the Python program that builds the module and assists pip with the installation.

Building and installing from sources

Using a virtual environment

The canonical way to build and install the package is to use setuptools with a build system. In Anaconda, this means you have to install

conda install setuptools build

Then you can issue the command

python -m build

from within the directory of this project. This command will create a new environment only with the libraries indicated in pyproject.toml and build your extension there.

The binary of this build process will be stored as dist/cython_example-*.whl, with some intermediate characters in '*' that represent the version of python and operating system or platform it was built for. You can install this binary on your system using

pip install dist/cython_example*.whl

Note that if you already installed a previous version, you can use the argument --force after install to force reinstalling the package.

Using setuptools

Alternatively, you can use

python setup.py sdist bdist_wheel

This requires that you have already installed the build dependencies enumerated in pyproject.toml.

Trying out the package

The file test/test.py contains an example of a program that invokes all functions from all modules installed in cython_example. Note how the functions norm1 and test are directly available form within the matrix submodule, because of the inline structure.

You might also like...
[DEPRECATED] YUM package manager

⛔ This project is deprecated. Please use DNF, the successor of YUM. YUM Yum is an automatic updater and installer for rpm-based systems. Included prog

A Poetry plugin for dynamically extracting the package version.

Poetry Version Plugin A Poetry plugin for dynamically extracting the package version. It can read the version from a file __init__.py with: # __init__

The delightful package manager for AppImages

⚡️ Zap The delightful package manager for AppImages Report bug · Request feature Looking for the older Zap v1 (Python) implementation? Head over to v1

Dotpkg - Package manager for your dotfiles

Dotpkg A package manager for your dotfiles. Usage First make sure to have Python

Simple Library Management made with Python

Installation pip install mysql-connector-python NOTE: You must make a database (library) & and table (books, student) to hold all data. Languange and

Library Management System

Library Management Library Management System How to Use run main.py python file. python3 main.py Links Download Source Code: Click Here My Github Aco

pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.

pipreqs - Generate requirements.txt file for any project based on imports Installation pip install pipreqs Usage Usage: pipreqs [options] path

A set of tools to keep your pinned Python dependencies fresh.
A set of tools to keep your pinned Python dependencies fresh.

pip-tools = pip-compile + pip-sync A set of command line tools to help you keep your pip-based packages fresh, even when you've pinned them. You do pi

Python dependency management and packaging made easy.
Python dependency management and packaging made easy.

Poetry: Dependency Management for Python Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right sta

Owner
Juan José García Ripoll
Quantum scientist and programmer. Proficient in C++, Python, Lisp and C, among other languages and environments.
Juan José García Ripoll
Package manager based on libdnf and libsolv. Replaces YUM.

Dandified YUM Dandified YUM (DNF) is the next upcoming major version of YUM. It does package management using RPM, libsolv and hawkey libraries. For m

null 1.1k Dec 26, 2022
Easy to use, fast, git sourced based, C/C++ package manager.

Yet Another C/C++ Package Manager Easy to use, fast, git sourced based, C/C++ package manager. Features No need to install a program, just include the

null 31 Dec 21, 2022
The Python Package Index

Warehouse Warehouse is the software that powers PyPI. See our development roadmap, documentation, and architectural overview. Getting Started You can

Python Packaging Authority 3.1k Jan 1, 2023
The Python package installer

pip - The Python Package Installer pip is the package installer for Python. You can use pip to install packages from the Python Package Index and othe

Python Packaging Authority 8.4k Dec 30, 2022
PokerFace is a Python package for various poker tools.

PokerFace is a Python package for various poker tools. The following features are present in PokerFace... Types for cards and their componen

Juho Kim 21 Dec 29, 2022
OS-agnostic, system-level binary package manager and ecosystem

Conda is a cross-platform, language-agnostic binary package manager. It is the package manager used by Anaconda installations, but it may be used for

Conda 5.1k Dec 30, 2022
OS-agnostic, system-level binary package manager and ecosystem

Conda is a cross-platform, language-agnostic binary package manager. It is the package manager used by Anaconda installations, but it may be used for

Conda 5.1k Jan 7, 2023
The Fast Cross-Platform Package Manager

The Fast Cross-Platform Package Manager part of mamba-org Package Manager mamba Package Server quetz Package Builder boa mamba Mamba is a reimplementa

Mamba 4k Dec 30, 2022
Conan - The open-source C/C++ package manager

Conan Decentralized, open-source (MIT), C/C++ package manager. Homepage: https://conan.io/ Github: https://github.com/conan-io/conan Docs: https://doc

Conan.io 6.5k Jan 5, 2023
A flexible package manager that supports multiple versions, configurations, platforms, and compilers.

Spack Spack is a multi-platform package manager that builds and installs multiple versions and configurations of software. It works on Linux, macOS, a

Spack 3.1k Jan 9, 2023