1+ <!DOCTYPE html>
2+ < html class ="writer-html5 " lang ="en " >
3+ < head >
4+ < meta charset ="utf-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Python Bindings for Raylib 3.7 — Raylib Python documentation</ title > < link rel ="stylesheet " href ="_static/css/theme.css " type ="text/css " />
7+ < link rel ="stylesheet " href ="_static/pygments.css " type ="text/css " />
8+ < link rel ="stylesheet " href ="_static/graphviz.css " type ="text/css " />
9+ <!--[if lt IE 9]>
10+ <script src="_static/js/html5shiv.min.js"></script>
11+ <![endif]-->
12+ < script id ="documentation_options " data-url_root ="./ " src ="_static/documentation_options.js "> </ script >
13+ < script src ="_static/jquery.js "> </ script >
14+ < script src ="_static/underscore.js "> </ script >
15+ < script src ="_static/doctools.js "> </ script >
16+ < script src ="_static/js/theme.js "> </ script >
17+ < link rel ="index " title ="Index " href ="genindex.html " />
18+ < link rel ="search " title ="Search " href ="search.html " />
19+ < link rel ="next " title ="Python API " href ="pyray.html " />
20+ < link rel ="prev " title ="Raylib Python " href ="index.html " />
21+ </ head >
22+
23+ < body class ="wy-body-for-nav ">
24+ < div class ="wy-grid-for-nav ">
25+ < nav data-toggle ="wy-nav-shift " class ="wy-nav-side ">
26+ < div class ="wy-side-scroll ">
27+ < div class ="wy-side-nav-search " >
28+ < a href ="index.html " class ="icon icon-home "> Raylib Python
29+ </ a >
30+ < div role ="search ">
31+ < form id ="rtd-search-form " class ="wy-form " action ="search.html " method ="get ">
32+ < input type ="text " name ="q " placeholder ="Search docs " />
33+ < input type ="hidden " name ="check_keywords " value ="yes " />
34+ < input type ="hidden " name ="area " value ="default " />
35+ </ form >
36+ </ div >
37+ </ div > < div class ="wy-menu wy-menu-vertical " data-spy ="affix " role ="navigation " aria-label ="Navigation menu ">
38+ < p class ="caption "> < span class ="caption-text "> Contents:</ span > </ p >
39+ < ul class ="current ">
40+ < li class ="toctree-l1 current "> < a class ="current reference internal " href ="# "> Python Bindings for Raylib 3.7</ a > </ li >
41+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#quickstart "> Quickstart</ a > </ li >
42+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#installation "> Installation</ a > < ul >
43+ < li class ="toctree-l2 "> < a class ="reference internal " href ="#dynamic-binding-version "> Dynamic binding version</ a > </ li >
44+ </ ul >
45+ </ li >
46+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#how-to-use "> How to use</ a > < ul >
47+ < li class ="toctree-l2 "> < a class ="reference internal " href ="#if-you-are-familiar-with-c-coding-and-the-raylib-c-library-and-you-want-to-use-an-exact-copy-of-the-c-api "> If you are familiar with C coding and the Raylib C library and you want to use an exact copy of the C API</ a > </ li >
48+ < li class ="toctree-l2 "> < a class ="reference internal " href ="#if-you-prefer-a-slightly-more-pythonistic-api-and-don-t-mind-it-might-be-slightly-slower "> If you prefer a slightly more Pythonistic API and don’t mind it might be slightly slower</ a > </ li >
49+ </ ul >
50+ </ li >
51+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#rlzero "> RLZero</ a > </ li >
52+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#help-wanted "> Help wanted</ a > </ li >
53+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#license-updated "> License (updated)</ a > </ li >
54+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#performance "> Performance</ a > < ul >
55+ < li class ="toctree-l2 "> < a class ="reference internal " href ="#bunnymark "> Bunnymark</ a > </ li >
56+ </ ul >
57+ </ li >
58+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#packaging-your-app "> Packaging your app</ a > </ li >
59+ < li class ="toctree-l1 "> < a class ="reference internal " href ="#advert "> Advert</ a > </ li >
60+ < li class ="toctree-l1 "> < a class ="reference internal " href ="pyray.html "> Python API</ a > </ li >
61+ < li class ="toctree-l1 "> < a class ="reference internal " href ="raylib.html "> C API</ a > </ li >
62+ < li class ="toctree-l1 "> < a class ="reference internal " href ="dynamic.html "> Dynamic Bindings</ a > </ li >
63+ < li class ="toctree-l1 "> < a class ="reference internal " href ="BUILDING.html "> Building from source</ a > </ li >
64+ </ ul >
65+
66+ </ div >
67+ </ div >
68+ </ nav >
69+
70+ < section data-toggle ="wy-nav-shift " class ="wy-nav-content-wrap "> < nav class ="wy-nav-top " aria-label ="Mobile navigation menu " >
71+ < i data-toggle ="wy-nav-top " class ="fa fa-bars "> </ i >
72+ < a href ="index.html "> Raylib Python</ a >
73+ </ nav >
74+
75+ < div class ="wy-nav-content ">
76+ < div class ="rst-content ">
77+ < div role ="navigation " aria-label ="Page navigation ">
78+ < ul class ="wy-breadcrumbs ">
79+ < li > < a href ="index.html " class ="icon icon-home "> </ a > »</ li >
80+ < li > Python Bindings for Raylib 3.7</ li >
81+ < li class ="wy-breadcrumbs-aside ">
82+ < a href ="_sources/README.md.txt " rel ="nofollow "> View page source</ a >
83+ </ li >
84+ </ ul >
85+ < hr />
86+ </ div >
87+ < div role ="main " class ="document " itemscope ="itemscope " itemtype ="http://schema.org/Article ">
88+ < div itemprop ="articleBody ">
89+
90+ < div class ="tex2jax_ignore mathjax_ignore section " id ="python-bindings-for-raylib-3-7 ">
91+ < h1 > Python Bindings for Raylib 3.7< a class ="headerlink " href ="#python-bindings-for-raylib-3-7 " title ="Permalink to this headline "> </ a > </ h1 >
92+ < p > New CFFI API static bindings. Automatically generated to be as close as possible to
93+ original Raylib. Faster, fewer bugs and easier to maintain than ctypes. Commercial-friendly license.
94+ Docstrings and auto-completion.</ p >
95+ < p > < a class ="reference external " href ="http://electronstudio.github.io/raylib-python-cffi "> Full documentation</ a > </ p >
96+ </ div >
97+ < div class ="tex2jax_ignore mathjax_ignore section " id ="quickstart ">
98+ < h1 > Quickstart< a class ="headerlink " href ="#quickstart " title ="Permalink to this headline "> </ a > </ h1 >
99+ < p > < code class ="docutils literal notranslate "> < span class ="pre "> pip3</ span > < span class ="pre "> install</ span > < span class ="pre "> raylib</ span > </ code > </ p >
100+ < div class ="highlight-none notranslate "> < div class ="highlight "> < pre > < span > </ span > from pyray import *
101+ init_window(800, 450, "Hello")
102+ while not window_should_close():
103+ begin_drawing()
104+ clear_background(WHITE)
105+ draw_text("Hello world", 190, 200, 20, VIOLET)
106+ end_drawing()
107+ close_window()
108+ </ pre > </ div >
109+ </ div >
110+ </ div >
111+ < div class ="tex2jax_ignore mathjax_ignore section " id ="installation ">
112+ < h1 > Installation< a class ="headerlink " href ="#installation " title ="Permalink to this headline "> </ a > </ h1 >
113+ < p > First make sure you have latest pip installed:</ p >
114+ < div class ="highlight-none notranslate "> < div class ="highlight "> < pre > < span > </ span > python3 -m pip install --upgrade pip
115+ </ pre > </ div >
116+ </ div >
117+ < p > Then install</ p >
118+ < div class ="highlight-none notranslate "> < div class ="highlight "> < pre > < span > </ span > python3 -m pip install raylib
119+ </ pre > </ div >
120+ </ div >
121+ < p > On most platforms it should install a binary wheel (Windows 10 x64, MacOS 10.15 x64, Linux Ubuntu1804 x64).</ p >
122+ < p > If yours isn’t available then pip will attempt to build from source, in which case you will need to have Raylib development libs installed, e.g.
123+ using homebrew, apt, etc.</ p >
124+ < p > < a class ="reference internal " href ="BUILDING.html "> < span class ="doc std std-doc "> If it doesn’t work, you can build manually.</ span > </ a > </ p >
125+ < div class ="section " id ="dynamic-binding-version ">
126+ < h2 > Dynamic binding version< a class ="headerlink " href ="#dynamic-binding-version " title ="Permalink to this headline "> </ a > </ h2 >
127+ < p > There is now a separate dynamic version of this binding:</ p >
128+ < div class ="highlight-none notranslate "> < div class ="highlight "> < pre > < span > </ span > python3 -m pip install raylib_dynamic
129+ </ pre > </ div >
130+ </ div >
131+ < p > < a class ="reference external " href ="https://electronstudio.github.io/raylib-python-cffi/dynamic.html "> Read this before using raylib_dynamic</ a > </ p >
132+ </ div >
133+ </ div >
134+ < div class ="tex2jax_ignore mathjax_ignore section " id ="how-to-use ">
135+ < h1 > How to use< a class ="headerlink " href ="#how-to-use " title ="Permalink to this headline "> </ a > </ h1 >
136+ < p > There are two APIs, you can use either or both:</ p >
137+ < div class ="section " id ="if-you-are-familiar-with-c-coding-and-the-raylib-c-library-and-you-want-to-use-an-exact-copy-of-the-c-api ">
138+ < h2 > If you are familiar with C coding and the Raylib C library and you want to use an exact copy of the C API< a class ="headerlink " href ="#if-you-are-familiar-with-c-coding-and-the-raylib-c-library-and-you-want-to-use-an-exact-copy-of-the-c-api " title ="Permalink to this headline "> </ a > </ h2 >
139+ < p > Use < a class ="reference external " href ="https://electronstudio.github.io/raylib-python-cffi/raylib.html "> the C API</ a > .</ p >
140+ </ div >
141+ < div class ="section " id ="if-you-prefer-a-slightly-more-pythonistic-api-and-don-t-mind-it-might-be-slightly-slower ">
142+ < h2 > If you prefer a slightly more Pythonistic API and don’t mind it might be slightly slower< a class ="headerlink " href ="#if-you-prefer-a-slightly-more-pythonistic-api-and-don-t-mind-it-might-be-slightly-slower " title ="Permalink to this headline "> </ a > </ h2 >
143+ < p > Use < a class ="reference external " href ="https://electronstudio.github.io/raylib-python-cffi/pyray.html "> the Python API</ a > .</ p >
144+ </ div >
145+ </ div >
146+ < div class ="tex2jax_ignore mathjax_ignore section " id ="rlzero ">
147+ < h1 > RLZero< a class ="headerlink " href ="#rlzero " title ="Permalink to this headline "> </ a > </ h1 >
148+ < p > A related library (that is a work in progress!):</ p >
149+ < p > < a class ="reference external " href ="https://github.com/electronstudio/rlzero "> A simplified API for Raylib for use in education and to enable beginners to create 3d games</ a > </ p >
150+ </ div >
151+ < div class ="tex2jax_ignore mathjax_ignore section " id ="help-wanted ">
152+ < h1 > Help wanted< a class ="headerlink " href ="#help-wanted " title ="Permalink to this headline "> </ a > </ h1 >
153+ < ul class ="simple ">
154+ < li > < p > Converting more examples from C to Python</ p > </ li >
155+ < li > < p > Testing on more platforms</ p > </ li >
156+ </ ul >
157+ </ div >
158+ < div class ="tex2jax_ignore mathjax_ignore section " id ="license-updated ">
159+ < h1 > License (updated)< a class ="headerlink " href ="#license-updated " title ="Permalink to this headline "> </ a > </ h1 >
160+ < p > The bindings are now under the Eclipse Public License, so you are free to
161+ statically link and use in non-free / proprietary / commercial projects!</ p >
162+ </ div >
163+ < div class ="tex2jax_ignore mathjax_ignore section " id ="performance ">
164+ < h1 > Performance< a class ="headerlink " href ="#performance " title ="Permalink to this headline "> </ a > </ h1 >
165+ < p > For fastest performance use Pypy rather than standard Python.</ p >
166+ < p > Every call to C is costly, so it’s slightly faster if you use Python data structures and functions when calculating
167+ in your update loop
168+ and then only convert them to C data structures when you have to call the C functions for drawing.</ p >
169+ < div class ="section " id ="bunnymark ">
170+ < h2 > Bunnymark< a class ="headerlink " href ="#bunnymark " title ="Permalink to this headline "> </ a > </ h2 >
171+ < table class ="colwidths-auto docutils align-default ">
172+ < thead >
173+ < tr class ="row-odd "> < th class ="head "> < p > Library</ p > </ th >
174+ < th class ="head "> < p > Implementation</ p > </ th >
175+ < th class ="head "> < p > Bunnies (60 FPS)</ p > </ th >
176+ < th class ="head "> < p > Percentage</ p > </ th >
177+ </ tr >
178+ </ thead >
179+ < tbody >
180+ < tr class ="row-even "> < td > < p > Raylib 3.7</ p > </ td >
181+ < td > < p > C</ p > </ td >
182+ < td > < p > 168100</ p > </ td >
183+ < td > < p > 100%</ p > </ td >
184+ </ tr >
185+ < tr class ="row-odd "> < td > < p > Raylib Python CFFI 3.7</ p > </ td >
186+ < td > < p > Pypy 3.7</ p > </ td >
187+ < td > < p > 33800</ p > </ td >
188+ < td > < p > 20%</ p > </ td >
189+ </ tr >
190+ < tr class ="row-even "> < td > < p > Raylib Python CFFI 3.7</ p > </ td >
191+ < td > < p > Python 3.9</ p > </ td >
192+ < td > < p > 7700</ p > </ td >
193+ < td > < p > 4.5%</ p > </ td >
194+ </ tr >
195+ < tr class ="row-odd "> < td > < p > Raylib Python CFFI 3.7</ p > </ td >
196+ < td > < p > Python 3.9 Nuitka</ p > </ td >
197+ < td > < p > 8600</ p > </ td >
198+ < td > < p > 5.1%</ p > </ td >
199+ </ tr >
200+ < tr class ="row-even "> < td > < p > Raylib Python CFFI 3.7 Dynamic</ p > </ td >
201+ < td > < p > Python 3.9</ p > </ td >
202+ < td > < p > 6300</ p > </ td >
203+ < td > < p > 3.7%</ p > </ td >
204+ </ tr >
205+ </ tbody >
206+ </ table >
207+ </ div >
208+ </ div >
209+ < div class ="tex2jax_ignore mathjax_ignore section " id ="packaging-your-app ">
210+ < h1 > Packaging your app< a class ="headerlink " href ="#packaging-your-app " title ="Permalink to this headline "> </ a > </ h1 >
211+ < p > You can create a standalone binary using the Nuitka compiler. For example, here is how to package Bunnymark:</ p >
212+ < div class ="highlight-none notranslate "> < div class ="highlight "> < pre > < span > </ span > pip3 install nuitka
213+ cd examples/textures
214+ python3 -m nuitka --onefile --linux-onefile-icon resources/wabbit_alpha.png textures_bunnymark.py
215+ </ pre > </ div >
216+ </ div >
217+ </ div >
218+ < div class ="tex2jax_ignore mathjax_ignore section " id ="advert ">
219+ < h1 > Advert< a class ="headerlink " href ="#advert " title ="Permalink to this headline "> </ a > </ h1 >
220+ < p > < a class ="reference external " href ="https://store.steampowered.com/app/664240/RetroWar_8bit_Party_Battle/?git "> RetroWar: 8-bit Party Battle</ a > is out now. Defeat up to 15 of your friends in a tournament of 80s-inspired retro mini games.</ p >
221+ < p > < a class ="reference external " href ="https://github.com/electronstudio/pygame-zero-book "> Coding Games With Pygame Zero & Python</ a > is
222+ a book for Python beginners.</ p >
223+ </ div >
224+
225+
226+ </ div >
227+ </ div >
228+ < footer > < div class ="rst-footer-buttons " role ="navigation " aria-label ="Footer ">
229+ < a href ="index.html " class ="btn btn-neutral float-left " title ="Raylib Python " accesskey ="p " rel ="prev "> < span class ="fa fa-arrow-circle-left " aria-hidden ="true "> </ span > Previous</ a >
230+ < a href ="pyray.html " class ="btn btn-neutral float-right " title ="Python API " accesskey ="n " rel ="next "> Next < span class ="fa fa-arrow-circle-right " aria-hidden ="true "> </ span > </ a >
231+ </ div >
232+
233+ < hr />
234+
235+ < div role ="contentinfo ">
236+ < p > © Copyright 2021, Richard Smith.</ p >
237+ </ div >
238+
239+ Built with < a href ="https://www.sphinx-doc.org/ "> Sphinx</ a > using a
240+ < a href ="https://github.com/readthedocs/sphinx_rtd_theme "> theme</ a >
241+ provided by < a href ="https://readthedocs.org "> Read the Docs</ a > .
242+
243+
244+ </ footer >
245+ </ div >
246+ </ div >
247+ </ section >
248+ </ div >
249+ < script >
250+ jQuery ( function ( ) {
251+ SphinxRtdTheme . Navigation . enable ( true ) ;
252+ } ) ;
253+ </ script >
254+
255+ </ body >
256+ </ html >
0 commit comments