CFFI: calling C from Python

Video in TIB AV-Portal: CFFI: calling C from Python

Formal Metadata

CFFI: calling C from Python
Title of Series
Part Number
Number of Parts
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Armin Rigo - CFFI: calling C from Python In this talk, we will see an intro to CFFI, an alternative to using the standard C API to extend Python. CFFI works on CPython and on PyPy. It is a possible solution to a problem that hits notably PyPy --- the CPython C API. The CPython C API was great and contributed to the present-day success of Python, together with tools built on top of it like Cython and SWIG. I will argue that it may be time to look beyond it, and present CFFI as such an example. ----- I will introduce CFFI, a way to call C libraries from Python. CFFI was designed in 2012 to get away from Python's C extension modules, which require hand-written CPython-specific C code. CFFI is arguably simpler to use: you call C from Python directly, instead of going through an intermediate layer. It is not tied to CPython's internals, and works natively on two different Python implementations: CPython and PyPy. It could be ported to more implementations. It is also a big success, according to the download statistics. Some high-visibility projects like Cryptography have switched to it. Part of the motivation for developing CFFI is that it is a minimal layer that allows direct access to C from Python, with no fixed intermediate C API. It shares ideas from Cython, ctypes, and LuaJIT's ffi, but the non-dependence on any fixed C API is a central point. It is a possible solution to a problem that hits notably PyPy --- the CPython C API. The CPython C API was great and, we can argue, it contributed a lot to the present-day success of Python, together with tools built on top of it like Cython and SWIG. However, it may be time to look beyond it. This talk will thus present CFFI as such an example. This independence is what lets CFFI work equally well on CPython and on PyPy (and be very fast on the latter thanks to the JIT compiler).
Presentation of a group Statistics Cryptography Multiplication sign Projective plane Control flow Total S.A.
Greatest element System call Beta function Code Latin square Mountain pass Multiplication sign Demo (music) Strut Execution unit Source code Survival analysis Parameter (computer programming) Mereology Computer programming Formal language Casting (performing arts) Semiconductor memory Object (grammar) Oval Endliche Modelltheorie Extension (kinesiology) Library (computing) Physical system Social class Metropolitan area network State diagram Wrapper (data mining) Shared memory Bit Price index 10 (number) Type theory Arithmetic mean Oval Order (biology) Interface (computing) output Right angle Pattern language Whiteboard Bounded variation Data structure Reading (process) Resultant Internationalization and localization Point (geometry) Web page Slide rule Functional (mathematics) Beat (acoustics) Password Mass Streaming media Event horizon Declarative programming Product (business) Number Attribute grammar Broadcasting (networking) Hexagon Population density Cross-correlation Integer Software testing Data structure Traffic reporting Condition number Window Multiplication Dialect Interface (computing) Poisson-Klammer Projective plane Volume (thermodynamics) Letterpress printing Line (geometry) System call Equivalence relation Inclusion map Subject indexing Word Pointer (computer programming) Personal digital assistant Function (mathematics) String (computer science) System on a chip Password Network topology Synchronization Social class Object (grammar) Game theory Window
Asynchronous Transfer Mode Functional (mathematics) System call Code Interface (computing) Binary code Computer program Code Compiler Computer programming Personal digital assistant Personal digital assistant Pattern language Cycle (graph theory) Data structure Asynchronous Transfer Mode
Standard deviation Trail Pairwise comparison Standard deviation Observational study Compiler Computer programming Product (business) Different (Kate Ryan album) Personal digital assistant Interpreter (computing) Object (grammar) Speicherbereinigung Data type Speicherbereinigung
Presentation of a group Module (mathematics) Interface (computing) Code Lattice (order) Spherical cap Object (grammar) Acoustic shadow Gravitation Speicherbereinigung Modul <Datentyp> Extension (kinesiology) Extension (kinesiology)
System call Machine code Code Multiplication sign Modal logic Demo (music) Strut Execution unit Source code Compiler Mereology Computer programming Area Medical imaging Pointer (computer programming) Web service Estimator Velocity Different (Kate Ryan album) Object (grammar) Logic Software framework Series (mathematics) Extension (kinesiology) Error message Identity management Area Email Electric generator Namespace Moment (mathematics) Interior (topology) Hecke operator Mereology Flow separation Type theory Digital photography Process (computing) Computer cluster Phase transition Pattern language Right angle Modul <Datentyp> Whiteboard Figurate number Arithmetic progression Electric generator Writing Functional (mathematics) Device driver Online help Rule of inference Event horizon Declarative programming Machine vision Revision control Goodness of fit Term (mathematics) Bipartite graph Operator (mathematics) Integer Implementation Macro (computer science) Compilation album Condition number Domain name Dependent and independent variables Graph (mathematics) Information Projective plane Expression Code Core dump Line (geometry) Ellipse Compiler Web service Function (mathematics) Revision control Video game Object (grammar) Game theory Extension (kinesiology)
before lunch break the next session and a policy of fire and we don't need presentation for sticker on army has been a long time on member of parliament community work by trying to find out what it means the you can few because this will be useful to the end of the war the these unified hands but in book and the book by 1 of the we need to have 1 by holds at every your Python that we can any this year so went OK so frustrated by what is it about the 1st survivor created the 2012 on needs the Latvian very successful projects according to download statistics of you wine uh when you consider move like 3 . 4 million nodes everyone's nowadays and it's actually is because the evangelical could and that means the main reason why it is so successfully that there are a few very successful project like cryptographic at and it's doing so so it means that every time you do begin cryptographically also actually influence fight as
dependency led by by by by probably a successful projects it's hard to say here and and the more data so that's something that signifies how do call C code from python right because because because obviously you you have go like everybody has equal that most libraries are there obviously system and if you want to call it into 1 of them then you need something so that I have just 1 more thing to 1 more solution to court C code from by I'm the names unified governed morning doesn't see for a function in interface um well shares ideas from multiple that actually so that the original modulation comes from the word to write its own if the fight with the is similar but then the then we took a lot of ideas from from other projects that siphons diet so and so on and so here is the devil that's anyone the according as a function from any anybody thinks system yet pw 9 uh what do you do when 1st you might get it out again and this young man page month convinced these like it says you OK you need to include reasoning that and then you get an assumption that you know that they takes the trust are argument the new strict Boston stops on on the feeding them and they just talk about what some have brought through these units like non BW password BW you I mean the lady is used by the UID T is always fine if you're programming and is on a massive Europe programming in Python so what do you do we see it value you write this goes in the bottom of tree we want to have a final conceive of have been given you to think about it in those not see triple quotes from report on here is the biggest trained on the next thing you you copy and paste parts of the money page like I'm going to say that they're in your editing except some not exactly sure it's in Ian's right could be long short whatever because see so so so I'm going to state that that that which which means in simplified use some kind of but I'm not sure exactly which kind of in and then using the structure us what is stated structure that has few pw your entities that but I know that the but then the structure that's what but instead of most of our ability to know what they are and we depends platform that you're running on the influence of the just kind that that the product for what do in an average year here right she here that that that are read and out of that's the source code is not meant to be a little bit glosses over the data right and then and then you could be based line for by W. name using OK and the end of the 3rd Monday also had something about includes so based on here some of our Declaration on this is that the set so as also said the good given name pw new ideas here of the name of something that we want to create OK so OK so you you input the input is the slides into 1 5 1 by find running the running on up to get rid of the unit is divided into all and now we can ever use UID survival all he is best known of pattern executive uh extension model so once you got it in your main program but what the main program just involving the politicians from these when and then it is something that has a contribute to write a function using function codes get every know new correlates underwent included you've got you're going to get strength password so so we can refuse it and you idea printed on this works so in this and the way we have played an interface to call this the function from Latin and that OK so so what I'm going to talk about knowledge yes not completely as simple as that being born in the and have to have some more examples of lots more conditions like those of line that actually this meeting with against 2 objectives with me that there is an equivalent object code if if I this and if I convinced generally and as such you may need to call at some point so that is the general had them uh yes sorry this is 0 so this is the 1st of all what about other things that you can do is see that you can get indicator function you can also have types of are completely or that but that does it is for example but you get if you ever seen has an interface like that can make a window into dense through window top but you don't need to know or care what is the time window then high window destroy window of this part the function the uh about about this in a very objective now In the project against against a few tens both for example if you really want to make the few structures like here wants to make a structure that is of type star and go so the then registrar brackets that concept means like if you know
that if you know the you know exactly what sovereignty is right so this is the general ideas our approach of the have thought you'd need to know a little bit of seeing but then if you don't know all the mean of the then easy because the same so we get we've have had a New York creating an object of type char broadcast on your initializing from a stream again in the summer the see that of the sobriquet and owns 12 bytes and you think if you can't actually it's the number of character plus 1 because there is a community in new character of variation the and you can and when you can index each you can read or write to induce of items you get you get also never kind of see that for example call users according to read before you need to get pw now when it 1st 1st we need the before and the example by dealing directly as trees but you can also needs a star brackets which means an array of characters like the the the on the on when in any case you get as a result Q which is actually an over that of that just pass the star money to me is that these events in memory and then you can index the and so you can get its contributes so those attributes that are just a few minutes of his so from these from such a pure you can also passed it's true void star to anything else these this use of gothic and custody to another point that I began test to an integer died like different costs if has a point anyone to really gets a number that violence a lot of these points are addressed and the cascades through an integer died on and I could have written it divided cost known all in that it instead I'm using that in the future t which is kind of history and efficiency tied to that means that only integer that is large enough to contain a pointer that just the same I'm getting a number that is integer value point so this is a kind of thing that means that if I take you who also have it if I stream of reason for example where a in my structure I have pw ideal careless 500 but that also BW names reading with density shall and then from this star star you can you can convert it back to Python 3 if you want to leave what if either string useful and so uh 1 example if you're doing something and it it more complex on you really want you have a Python objects like this it's is it's in the thing that I want to I want to have this on an objective constant to avoid star that's a C-code will just carry around and then at some point it does the Goldman gave us back the voiced stops and from that point so I want to go back to the python object I mean this kind it is still not for a in order quarterback systems that if you raise cost but also for the library typically you you really is the beta function the board by on use it's some kind of void star argument that says that we just on the we needed by on called like so also in order to do that you you you would use a find a new kind of cast in the back and object to avoid then you see the way should the game against avoid stuff that happens to contain the same points the same volume of the voice stuff and then from this value you can go back to the original peaks objective using evidence from hundreds of this is just 1 example of more advanced things well simplified the whole supports more as the food the language regions lecture notes so huge and I mean about foods united I mean of course not so that the food declarations of the like what you can't what's types you can declare what's what how you how you can call functions values use 14 conventions and so on so forth that when Windows the and on Windows C. dental present std that no STD cord story and it is supported by the the user is more than distraught of that and line like if you really want if you have some larger and larger library fantasy every event and they think that when a typical example is the solution to the library when you don't want to expose directly as library that is they want to explore some kind of Python some kind of Python interacting of another read for what you do is you write your Python wrapper but itself you see if I can use it internally that you write your classes on nice functions in by then on the inside and then you would use we see that the object that you would not actually expose them to the rest of the users of these reviews rather that you're writing so what is it is difficult to integrate many green instead of right instead of writing for example the back the accession what you where you would write in C. the beats everything that you write your the native title and so on and so forth and then and then you get when you see extensions see that people important you directly here we that that is more that what's the very important is directly with the use of Python thereafter that it said using In the land is
there are actually a few over use case of the notes for his people about now you can use the unifying modes that is called ABI as opposed to a P i in which in which is the way in which modes where you don't have any cycle binary in for that always understand when you get more nights he died as in you have to to declare exactly your structures and your functions on your the nodes to make a on the end of the road to use that but the current current you know that that that that thing but shows patterns and also support for invading instead of extending which is which is the case where you have your big program that is written nothing but toward just wants to import unused by for embedding so for this case there is a lot of the other 5 in which you can write so you write Python code you declare you need to know we see that the thing in declaring the death becomes the interface that is 40 from the C code and then the rest of the program of course interface and course into your body code directly OK well here's
about the documents yes so is
the what I for about 3 minutes but they abandoned that but there is different from the standard we did see that the middle of race speed when run by by get than in the breath that from that of the and less about the lives of study from the 4 instead of 3 Greek land find the problem but otherwise it just the same thing Europe by myself my program that I mean by that kind of problems productivity comparative private schools the track is and by the Senate the
main difference in the main difference is that when for example it's intended to be a very different kind of garbage collection about things moving international agreements gathered from the case you don't know what we expect them to needs fine when this is is what they
mean more research because it is moving garbage collector we have traveled intimate things of by CAPS interface so so it's hard for to import survive and C extension is possible because of the gravity of the meeting and present is slow front so it's kind of works I would say I would say
save you will see that there and that the other thing we can mostly do it for by for example nowadays mostly so soon and also invented rather and fact great
right now if you if you if you use Python and don't rely on a lot of the with you for example everything as that of examples of where web services are likely to be important and lost right whatever huge libraries that response to begin with 14 patterns of it was during the it was the the gaze legends and myths of the environment and but when I would I would identities that that's this C API of the event was affected part of the success of the right type of Python the historical success of by the wideband and world and started to be really useful like 10 years of rule or 15 years so if you also because it has to be the please see API on people actually use it to to actually did interesting things on top of it but that's my on and on and on your audience or is binding generators of having been built on top of it so you don't need but you can write succession manually but you can also use these other tools that would generate extension for your unsupervised just 1 more such tools as well as different as a series phase of it's different I would say because because the going really not expose any part of the back and the API as in yes you can write C code with to 5 but this this encoded that you right should not use any hi objectives stars or any time In from longer or any of its function from so we think that it means also that it in that it is possible to import this cool 68 of I want you to order in presidency back and that's what we did so that's 1 of the motivations for C and find the 1st place is that it is possible to rights high high version of the of the fight and indeed we did on this example is that the more from the is science in the start of his through when it was just exactly the same 1 that was the best in all of fact when it is actually faster on the of bipartite because by bias due combine noses the velocity of the fine is able to go by to come to to really machine code that we directly causes the function for example so it's extremely fast thinking about that but don't make does not mean that it's extremely slow and what you got and the receiver of the performances except the the various walks in the bottom and that it would be easy to boards to other conditions has not been done so far the potential telling or and pattern so yes that the main benefit is that it is independent on in Normandy depends on the severity of the API
that have you see if the value is included in the support of line on the back of vision is a population of like without being the German or the missions this 1st um a have million 1 of the working with C of a fire like a few years old I also leads what mainly on knowledge and reduce us based I have to use framework and they encounter like it was really hard to create a when you have a complex phrase to Kraepelin have so so that it was written by an older headers and to a feed them to see if the fight to create their their they library so uh I actually it wasn't document that that they might the moment it's now but you can actually run their use compiler do you have to break on by the your head so that the user can synthesize improved if not now it's now now it's clearly separated the 2 was that process that you really rewrite separated by the speed of declared what you want and you run it once you get your accession when you're and then you the from domain program so it's better than it used to be yes I don't think so token that's the cold I have a question about by by actually there there ask you because there is no separate by by Talcott seems out what is the status of uh by 3 work there like it would be nice to get to 3 . 5 in areas the and you're a senior it's good idea if I were to give an estimate of time and like I can image in the back with unit unit of time I would say that the next year or it should be organized in progress to us by 3 . 5 yes and what kind of help do you need to so many people a few years needs the people died in them and many of the Vietnamese I think you have another question about the book by by a and there is some kind of tool tool embed by by like by a silo by 2 weeks something like the user to embed them the urge to root of binary so of and I don't know know is that after having more question is a I'm the wrong person to ask if it was that yes necessary information thanks to the talk thinks about politics will receive the fights amazing guy use it quite often and I was wondering when you have the declarations with the ellipses life doubletalk that'll get you figured out the heck can you like in very simple terms how it goes out and find out because it always works great that that is for example you would to use some kind of integer but don't know which of those so so the semantic is a semantic is to right 1 C 1 piece of C code that will want to the by combining it with enormous single by the source of most of our when everything of everything in 1 of these that that that is a different kind of magic like for example that lived in and around the uh it's probably probably contains uh must have the goal of the game thank it is the years estimate the I mean it must not be something like like like you he writes 1 being the expression that's a size of new ideas point 1 1 question mark is then I'm going to use these errors the size of graph to within wing the use of the fact of that then then you do it makes for a round of magic know if it's signed off on something like that I mean for for scientists and findings unless you big minus 1 you got do you added the and you ask it is it's going to be now so we're at the end of the normal sessions said time from 30 minutes but uh photo the varietal a quarter to so people are just more questions and sit around but just want to to let you know that if you have to do something or how fast you have to do it now introduction to question about to define we have a project with a lot of were defined that are constructed dynamically during compilation from a look of nested macros entered possible to use them by name being uh in near a Python code because actually I don't know they're waiting for the environmental conference but have example of we have a driver of that to use some of the cool operations and these early heard comments are constructed from being that markers that shit have no work what they're doing some some source some worse the union contain errors I mean you and out that I really need immediately you think is a here in Cedar uh some harsh defined name space but that means it's some integer and no which 1 figure it out what I any more questions it will think you almond and so you that you have thank


  411 ms - page object


AV-Portal 3.21.3 (19e43a18c8aa08bcbdf3e35b975c18acb737c630)