{"id":16127438,"url":"https://github.com/novocaine/rust-python-ext","last_synced_at":"2025-03-18T14:30:25.171Z","repository":{"id":32978176,"uuid":"36601626","full_name":"novocaine/rust-python-ext","owner":"novocaine","description":"Distutils helpers for rust Python extensions","archived":false,"fork":false,"pushed_at":"2017-03-18T17:57:07.000Z","size":32,"stargazers_count":67,"open_issues_count":2,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-28T10:02:35.287Z","etag":null,"topics":["cargo","distutils","python","rust"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/novocaine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-31T12:16:55.000Z","updated_at":"2024-11-28T16:31:11.000Z","dependencies_parsed_at":"2022-08-07T19:16:23.934Z","dependency_job_id":null,"html_url":"https://github.com/novocaine/rust-python-ext","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novocaine%2Frust-python-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novocaine%2Frust-python-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novocaine%2Frust-python-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novocaine%2Frust-python-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novocaine","download_url":"https://codeload.github.com/novocaine/rust-python-ext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243933378,"owners_count":20370989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","distutils","python","rust"],"created_at":"2024-10-09T21:44:13.020Z","updated_at":"2025-03-18T14:30:24.922Z","avatar_url":"https://github.com/novocaine.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rust-python-ext\n\n[![Build Status](https://travis-ci.org/novocaine/rust-python-ext.svg?branch=master)](https://travis-ci.org/novocaine/rust-python-ext)\n\nSetuptools helpers for rust Python extensions.\n\nCompile and distribute Python extensions written in rust as easily as if they were written in C. \n\nWell, maybe easier - it's rust.\n\n## Example\n\n### setup.py\n\n```python\nfrom setuptools import setup\nfrom rust_ext import build_rust_cmdclass, install_lib_including_rust\n\nsetup(name='hello-rust',\n    version='1.0',\n    cmdclass={\n        # This enables 'setup.py build_rust', and makes it run \n        # 'cargo extensions/cargo.toml' before building your package.\n        'build_rust': build_rust_cmdclass('extensions/cargo.toml'),\n        # This causes your rust binary to be automatically installed\n        # with the package when install_lib runs (including when you \n        # run 'setup.py install'.\n        'install_lib': install_lib_including_rust\n    },\n    packages=['hello_rust'],\n    # rust extensions are not zip safe, just like C-extensions.\n    zip_safe=False\n)\n```\n\nYou can optionally pass additional arguments to cargo through build_rust_cmdclass - see \nhttps://github.com/novocaine/rust-python-ext/blob/master/rust_ext/__init__.py.\n\n### Result:\n\n```\n➜  example git:(master) ✗ python setup.py install\n\n.. yada yada yada ..\n\nrunning build_rust\ncargo build --manifest-path extensions/cargo.toml --release\n    Updating registry `https://github.com/rust-lang/crates.io-index`\n    Updating git repository `https://github.com/alexcrichton/pkg-config-rs.git`\n Downloading regex v0.1.38\n   Compiling pkg-config v0.3.5 (https://github.com/alexcrichton/pkg-config-rs.git#42f1704b)\n   Compiling regex-syntax v0.1.2\n   Compiling rustc-serialize v0.3.15\n   Compiling memchr v0.1.3\n   Compiling aho-corasick v0.2.1\n   Compiling regex v0.1.38\n   Compiling python27-sys v0.0.6 (file:///Users/jsalter/dev/rust-cpython/python27-sys)\n   Compiling num v0.1.25\n   Compiling cpython v0.0.1 (file:///Users/jsalter/dev/rust-cpython)\n   Compiling hello-world v0.0.1 (file:///Users/jsalter/Documents/dev/rust-ext/example/extensions)\n\n.. yada yada yada ..\n\nInstalled /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/hello_rust-1.0-py2.7.egg\nProcessing dependencies for hello-rust==1.0\nFinished processing dependencies for hello-rust==1.0\n\n➜  example git:(master) ✗ python\nPython 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)\n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information\n\u003e\u003e\u003e import hello_rust\n\u003e\u003e\u003e hello_rust.hello()\nRust says: Hello Python!\n```\n\n## Getting Started\n\nInstall:\n\n```\npip install https://github.com/novocaine/rust-python-ext/zipball/master\n```\n\nNote that I didn't ever upload this extension to pypi - the version that's\nthere has been put there has been uploaded by someone else and is old.\n\nCompile the example:\n\n```\ncd example\npython setup.py install\npython -c 'import hello_rust; hello_rust.hello()'\n```\n\nIf you are not pretty confident with Python C extensions already, it is recommended that you base your project off the code in the example directory. This gives you a sensible layout and something that is already compiling.\n\n## Notes\n\n* Supports Python 2.7 and Python 3.6 on Linux and OS X (tested by travis CI)\n\n* Unlike distutils, rust-python-ext delegates all rust build decisions to cargo. \nSo you can't pass compiler args to the compiler from setup.py. This is by design. Cargo's awesome - use that. \nYou can however pass args to cargo which might then influence what it does.\n\n* If you want to access the python C API from rust, use https://github.com/dgrunwald/rust-cpython. The example dir contains a project that shows how this is done.\n\n* If you don't explicitly pass `ext_name` to `build_rust_cmdclass`, your\n  extensions will be be named according to your lib's name in `cargo.toml`,\nwith the `lib` prefix stripped out so that it looks like a regular Python\nmodule as per the c-ext convention. If you want it to start with `lib` or be\nnamed something else, pass a value to `ext_name`.\n\n* This should interop just fine with other C-exts or cython being in the package, although I haven't tested it.\nThe cmdclass approach is minimally invasive and is how, I believe, the setuptools god intends things to be. There is no monkey-patching or hacking of distutils internals.\n\n* As per the above, you don't *have* to use the supplied cmdclass helper for `install_lib` if you don't want to, it just means that `install` will automatically trigger `build_rust`.\n\n* You can use `setup.py develop` to put your module's code on PYTHONPATH\n  without installing it, as you can with other extensions. This automatically\nenables --inplace.\n\n## TODO\n\n* Windows\n* An example using CFFI and/or ctypes\n* `clean` command\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovocaine%2Frust-python-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovocaine%2Frust-python-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovocaine%2Frust-python-ext/lists"}