 Hi, everybody. Welcome back. Again, I'm Austin Bingham from 16 North up in Norway. I want to introduce Chris Klaus, who will be talking about, as you can read, Pythonista, a full-featured Python environment for iOS devices. Take it away. Thanks, Austin. Hi, folks. My name is Chris Klaus. So I'm relatively new to Python. I started computing on a 64-kilobit Commodore machine way back in the day. So I've done basic COBOL, RPG, languages you don't even know about anymore. I've also done a lot of Java. I worked for Sun, so working on Java. Worked for seven years for Apple doing development there. And now I work for IBM. And what I do for IBM is I do smarter city software. So I have a group of architects who help customers do smarter city software. And at the end of the day or on a long flight, it's really fun to just break out the iPad and hack on Python. So that's what I'm going to try and show you a little bit about a hobby that I have on off-hours, hacking around with Python on iOS devices. So Pythonista is written here in Berlin by a gentleman named Oli Zorn. And I've never met Oli. I hope to meet him later today for the first time. But he writes two products. He writes two iOS apps. The first one is called Pythonista, and that's what today's focus is on. The second one also uses Python, but it's much more for workflows. It's called editorial. And by workflows, I mean I'm a blogger. I go to various conferences and I write blogs. And I want to upload my blog. I might want to do some editing of it. I might want to do all sorts of interactions on the text, convert it to PDF, convert it to HTML, convert it to whatever format. And editorial is really slick for that. So I personally gravitate towards Pythonista because it's really about writing Python and living in Python. But lots of editorial-type folks, people who deal a lot with text, documents, love editorial and love its workflow. So I'll focus mostly on Pythonista today. I'll try to show you a little bit of editorial if we have time later. So just a little bit about what we're going to talk about. What I wanted to do was focus in on this particular issue here that Apple puts a lot of constraints on developers who want to develop applications which are coding platforms for iOS devices. Their principal worry is that you can download scripts that can change the machine. And so there's a lot of constraints around being able to download code into an environment like Pythonista and upload code. And so there have been times in the past when Pythonista has been booted out of the App Store by Apple because it sort of crossed the lines. And so we play a very delicate game as a community trying to make sure that what we do with Pythonista doesn't go beyond Apple's guidelines or they actually take the app out of the App Store. So very interesting thing. We have a really strong community with a community forum and I'll show you a little bit of that. The internet here is lousy so I'm not going to show you it live, but I'll show you a little bit of the UI. There's also specific modules that have been put into Pythonista for dealing with iOS things like graphics and sound and things like that, but also for dealing with third-party things like Dropbox. So I'll talk to you a little bit about that. And I'm really going to try to focus most of it on showing you actual apps are running. And okay, so that's the main webpage for Pythonista. Again, you get the idea. It's a Python environment. It's Python 2.7.6 running on iOS devices. And yes, you can run this on your iPhone. Yes, you can run this on your iPod. So yeah, it's a full environment. And it's got a great code editor to it that lets you edit code on the device. But also if you have a Bluetooth keyboard, lots of the people in the community use a separate Bluetooth keyboard and that's the way they enter their text. It's got modules for graphics and touch that I'll show you. And it's got just recently added NumPy and Mathplot Live, so I'll try and show you those. And it's now got a GUI toolkit. So you can build an application with a graphic designer that looks and feels like a real iOS app like to an iOS user. You can actually put that into the Apple code tool and then you can upload it to the Apple app library. So you can make a full feature running app that looks like an iOS app on your iPad. And you can put it in the Apple app store. Okay, so the docs are all online. They're also all in the iPad. So that's a beautiful thing. If you're on a plane and you forget about some standard library function call or you forget about some module that Oli has provided in the tool, it's always online. So I'll show you that. It's a full feature 2.7.6. There's very few things that are a little bit special about it, but it's really a full feature 2.7.6. It also includes these special modules that are specific to dealing with the iOS, things like knowing your location, doing reverse geocoding, which is really beautiful. So take the location of this device and turn it into an address. So I know the street address of the device at any moment. 2D graphics in a thing called scene, sounds, speech, and then this new UI component that lets me create real UI on the iPad that looks and feels like any other iPad app. Then there's tools like clipboard and editor that lets me get at the clipboard of the iOS device and at the editor of the text that I'm dealing with so I can actually manipulate the text of the editor inside. Key chain for passwords and things like that. Next up, there's some extra modules that are just great things to have like beautiful soup and requests and these are just modules that are lots of users want and so Oli includes them. The difficult thing about this platform is it's not really ready for downloading modules like you might be used to on your Mac or your Windows box, so you can't just go out to Pi Pi and download modules into your device. The community has done a pretty good job of letting you download modules that are pure Python, but if modules include C, you've really got to work hard to get them into this environment. Again, he includes lots of good libraries right out of the box, which are quite useful, in particular the Dropbox functionality is really a lifesaver in some instances. Then last but not least, there's a rarely active community. This is a snapshot of the community this morning. Somebody's just uploaded a new game that they want to show off to people and get them to collaborate. The second one down here, he's tried to rotate text and he's having trouble and he's asking questions of the community. A really active community, one around Python, one around Editorial that are really useful. Then last but not least, the community has relatively recently created a Python Easter tools on GitHub. This is really a collection of code that's been specifically built on top of Python Easter. It lets the community point to tools and get collaboration around those tools. Through GitHub, we have multiple people editing up tools, games, whatever they might be on the platform. There's other pythons on the iOS. I thought it would be useful to just talk about those. I think by and large, these are things that are useful to steer clear of with maybe one or two exceptions. Editorial, as I've mentioned, is the sister product. I'd really encourage you to look at it in addition to Python Easter. This new one is called Computable. It's just come out. It is an iPython implementation that has MatPly lab and NumPy and all that good stuff. This one is looking good, but it's 1.01. It's brand new to the market. It comes out of Austria and the creator has been a contributor to the Python Easter community and now has come up with this new thing. It will be interesting to see the dynamic between Computable and Python Easter. I think those are really the two to look at in this space. The other ones come from various places around the world. The ones that I really encourage you to steer clear of are these two. They look interesting, but they're very long in the tooth and they haven't been supported in many years. There are other ones out there, but these are the ones I recommend. Last but not least, this is what it looks like. I have a list of files on the left. I have the file I'm currently working on on the right, and that's my last slide. From now on, we're just going to live inside Python Easter. This simple file just uses the speech library. What I thought I would show you is that there's a thing called speech. Are you talking to me? Are you talking to me? Are you talking to me? If you know a taxi driver, it might make sense. That's just a simple module that Oli's built into the tool that lets me take arbitrary text and pump it through a text-to-speech engine. It can take multiple languages and it's very flexible, but sometimes just useful and fun. First and foremost, let's start with console. It's got a standard console like you might be used to. If we go over to the console, I can type stuff here. Standard console that you're all used to. I can also do graphics to the console. Let me take a simple mathematical formula that draws a star and let me draw to the console. I can draw either graphics or pump text into the console. Again, it's the standard Python console that you're used to. Let me clear that. Next up, there is a module that lets me do a bit more sophisticated graphics. It came after the console graphics. It's called Scene. Scene is basically I get to use the iOS visual display and do various things with it. I'll show you a few of these. When I create a scene, I can either create it in landscape or portrait because the device can turn. If I do it right, I can create it such that a game or anything else could respond to turns so that my game could play the way. First, I'm going to show you a game called Cloud Jump that was initially put up on the forum. The author said, hack at it. Tell me what you think. The problem for us is, for me, is that it's sideways. I'm tilted. I'm going to play. If I can. Okay. Now it is tilted. I'm going to play Cloud Jump. Stay connected. Do you guys got that? It's one of those. On the iOS devices, you always pick something that's geographically close to each other. They're not exactly secure passwords. Cloud Jump lets me bounce off of clouds. If it's playing for you, you can see that it lets me. No high score, no sounds, no nothing. So great, great, nice tool that a guy actually built with this young child together. They built this as a programming exercise. He's actually built three or four of these games, Jumpy Octopus. There's a Times Table torture. He's created these games with his kids. So he put it up on the community and let the community have at it. What the community did was add high scores, add sounds, add the ability to play in either direction, et cetera, et cetera. So if I got a high score, I got to give it my name. And it's a different game. It's got monsters. It's got a different character. I can pick my character, et cetera. And so now it's got sounds. And if I die, it's got explosions, all those sorts of fun things. So again, through the joys of GitHub and Open Community, people can take something that started as simple, make it better and better together. So a lot of what I do use it for is things related to my work. So again, my work is about smarter cities and I work with cities all around the globe trying to help them figure out how to use data about their city to deal with problems like water and transportation and public safety and things like that. A huge trend in cities is open data, where cities are taking their data and they're publishing it to developers and letting the developers to run wild to build apps. And so a lot of what my work has been about is about showing people the art of the possible. So here what I've done is I've taken four data sets and I've had specific formats for them. And I let people go out and create extracts of those data sets that are then stored locally. So again, I'm going to go out to a city's open data. I'm going to grab a couple data sets that I want to deal with. I'm going to get on an airplane and I'm going to whack at it with numpy and matplotlib. So this is a way for me to deal with the disconnectedness of I want open data and I got the tools but I'm on an airplane and the airplane doesn't have Wi-Fi. So a simple app that I'd run for you if we actually had good internet here, but we don't, to grab data sets and put them into a format that can be used for matplotlib. The other thing that that I do around Smarter Cities is we actually sell a tool and that tool helps people run traffic or water, public safety or complex stuff. That tool has a REST API and so what I can do is build into my iPad the ability to talk to some huge system out in the cloud and use that REST API. So here I have a really nice graphics rich platform that I can create a really slick dashboard for the mayor or for the guy who runs the transportation office and I have a pretty simple straightforward way to go to a REST API and pull out all sorts of real-time data about traffic as it's going to be an hour in the future or where the leaks in my water system etc. So again I'll show you those but the internet here is lousy. Let me talk to you one last thing about scene and that is color. So this is called tilting color and basically the idea is that I'm looking at the pitch yaw and roll of the iPad so I have a sensor in the iPad that tells me the pitch yaw and roll and I can change the color. This was just to prove that we could build demos and games around pitch yaw and roll but it's a simple demonstration of what I can do with the scene. So a very short piece of code just grabs the pitch yaw and roll and lets me play with it and show it off on the scene. Okay one of the people in the community built a game of life. I'm going to run this so I want to make sure it's gonna okay and then I think I double tap. Give me one second. Okay your standard game of life and again these things go up and then they get improved by the community. The context module lets me go into the address book of the iOS device so I can go grab all my contacts and do various manipulations of them. This code just goes out and grabs my contacts and uses the geocoding to give me their lat-long of where they live so I take the address out of the address book and I use the geocoding to turn that into a lat-long. So again really short piece of code does some interesting things and can be grown on. Recent tweets goes out to Twitter and basically for a user tells me what are their recent tweets. So I can do these sorts of things that you guys can write down my key here if you want. I can go out and go to Twitter or do lots of screen scraping sorts of things with requests and beautiful soup and all those basic tools. Let's talk a little bit about UI. So this is the UI tool that comes with the package. It lets me create all the things that you see here. So I can create labels and buttons and sliders and switches and calendar pickers and all the rest of the usual stuff that people expect out of iOS apps and basically what it will do is it will create a file that's called name.pyui and so that pyui file really defines a user interface and I can basically just load in that file at startup time and I have a UI that's ready cooked ready to build with or if I want I can build the UI piece by piece by piece in Python. You have your choice. Some people seem to like the design tool and laying out their UI and really making it nice and then just sucking it all in as one piece. Other people like to build it up piece by piece by piece in Python. So let me just show you a little bit of what that looks like in actual reality. So here you can see I can add new objects and so I can say that I want to create an object. I want to create sub-use of that object etc etc. So just a really slick little addition to the tool. Weatherware UR again was a simple tool that uses the geolocation of the current object and then uses an open data weather service called weather underground I believe. Just trying to see. No it's called open weather map open weather map dot org. So again this tool just gets the geolocation of the device turns that into a city-state country and then goes out to the open weather maps dot org and gets the current weather so it tells me temperature pressure humidity sunrise sunset etc. So again simple tools that get created quite rapidly that use the sensors in the device either the location sensor the pitch yaw roll sensor and the various the touch sensors the various sensors inside the device. And of course there's the Zenf Python right so this is another thing that just writes to the console and as it's writing to the console the import this text it is doing so I'm changing the color slightly. All right just trying to see if I covered what I wanted to cover. Oh matplotlib and numpy so here is a a plot out of matplotlib so if you're used to using these tools and know how to make them go they're all here fully functional and and quite quite useful and powerful. I think it's it's it's created a lot of excitement in the community having tracked Python for iOS for a long time it was like really a commonly requested thing to get it here and it's just come to market in the last four months. So it's all in there and people are really starting to go crazy with it. It doesn't have the the Python Eastern environment doesn't have a search tool to search all the files so I can do that so I created my own and basically what it does is it goes grabs all the files and looks for it's like a grep. It brings up something that that's useful so I can either tap this arrow at the upper right corner of the screen to run or I can tap and hold and if I tap and hold it will let me give command line parameters right so you gotta usually when you're typing at the command line you'd like to give your Python app script other command line parameters so you can run with arguments and so this this tool will do that and bring the the text up in in the editor with the the text highlighted. I think I've showed you what I wanted to show you I'm open to questions go for it docutils let me see okay um yeah there's a whole sound um library so let me let me go there so uh this is good because it it lets me show you what what it looks like to to be a developer on the environment um so here's a module called sound um it's got samples and whenever there's samples I can actually open those samples in the text editor right away and just run them okay so that plays a short melody um and let me go back um so load effect play and effect stop and effect and set volume um there was also some undocumented features inside the sound library that that parties are using so um that's another thing that goes on in the community is people um sort of go through the code and find undocumented features that that are useful but a pretty straightforward simple sound library yes sir portable is there any has anybody written something that's kind of a layer above that that has the iOS driver yep yeah so so not particularly for sound but for other things I have seen the the community build up sort of a a wrapper around various libraries but but not for sound that I've seen there was a question in the back oh I'm sorry yeah no I'll I'll repeat the questions I'm sorry yeah okay um so so first and foremost one thing I didn't show you is that I can put certain scripts into a actions menu right these these are things that I do often one of those is dropbox sync and I'm just going to try a dropbox sync it probably won't work but maybe the internet's good enough um so so dropbox sync lets me push my scripts into dropbox I can then get on my windows box or thankfully my my mac and and use those use those scripts so moving things onto and off of your device can be done through this this community built tool that is built on top of the dropbox module the nice thing about that is I can then dropbox sync on my iOS device on my on my phone and I I have code base synced between my two iOS devices now your question was different than that your question was how do I take the app that I've built here on my iPad and how do I get it into the Apple App Store so so so basically you what what's the code tool that Apple uses I can't remember what it's called Xcode there we go um basically you take your Python files and um you put them into Xcode and then there's one script one Python script that you need to run on your Mac to create resources into into that project and then you build that project and it builds down to an iOS executable and that iOS executable is something that you can put up on the app store so again take the code from here and sync it to your Mac probably using Dropbox sync but there's lots of ways um second run this script on your Mac which creates extra resources inside your Xcode project compile your Xcode project and you have an iOS app that's ready to go into the iOS App Store I don't know the answer whether you can run it in the iOS emulator on the Mac I just not familiar enough with that piece of the puzzle to say my suspicion is that it does not but I would need to check that yeah so so that's an awesome point it's it's really really hard to develop on an iOS device on a touchscreen but we've seen people build really complex games on an iPhone they sit on a bus every day on their ride home from work and over 10 days they built a really complex app on their iPhone so it's a really small screen with really teeny editor and all the line-wrapping problems they have but I gotta tell you that the majority of the serious people who really do work on on Pythonista use an external keyboard it's like essential I actually don't I don't use an external keyboard but most people do so um yeah I I think you're right that that that it's hard to um to develop um on the on the iOS device alone and not be able to emulate on the Mac and again I just don't know the answer whether that's doable or not doable I just don't know yeah yeah all that stuff so the question was can you can you access um Excel files and JSON and all that stuff yeah the standard JSON libraries in there um you know reading through files is is really easy and and actually you know if you if you really love file manipulation Jeff definitely check out editorial too because editorial has has workflow to it um that that Pythonista doesn't for for making that that easier there's also lots of conversion capabilities like I want to convert this whole thing to a PDF or I want to convert this whole thing back into Excel so so there's lots of lots of good code snippets and and work done by the community to do that so let let me show you two more things um so um this is Compute Table this this is not created by Oli it's it's sort of a computing product um it is an ipython implementation for the ipad um and so basically um you know the full ipython story um but but you know reformatted to work work here um and I'm just gonna open up a uh gonna open up a uh a book whatever they call those um and here you can see um all all the usual things you'd expect from a from an ipython world um he's giving you some samples um where you know he he shows you how he computed the logo of the app itself um and so um so again there's uh there's that tool which again if you're into ipython and and and that sort of style um I would definitely recommend and then um last but not least let me show you editorial which might be here and the editorial is created by Oli so it's the sister product to um to uh to pythonista um and you'll see it looks a bit different um let me just see if I can find one of these you you can see that it's got more of the ipython look and feel where I where I can create a user interface that that feels like a webpage um but it's got more tasks and is more task oriented um and again based on sort of let's let's deal with markdown first and foremost but let's deal with lots of other file formats um in addition other comments questions and issues um I'm a big champion of that um I'm a big believer in that uh so far um the really the only python 3 um that I know of is is really in the other packages um that I don't really recommend so I got to say that there isn't a great python 3 on iOS today um we bug and pester Oli about it but but for him it's it's a biggie right so um a lot of people say they want a single app that's got python 3 and python 2 um but if you think about that that's really really hard from a developer's perspective and from a user's perspective first from the developer's perspective he's got to have two sets of docs two sets of standard libraries two sets of worries and debugging in an environment that does both is really hard the other the other way to go is to create two separate apps where he's got you know python is to 2 and python is to 3 and and you know the the thing that he says over and over again is it's a disruptive break for the for the users you know it's it's going to create a whole lot more questions on the forum about I this used to work and now it doesn't work and I don't understand the difference between python 2 and python 3 there's still a lot of quandary in the community so um right now um you know computable is python 2.7.1 um python east and editorially or 2.7.6 um we're just not there with a great with a great python 3 just yet go for it no well so so I can use dropbox sync in two directions right so I can do that trick um I can mail myself things right pick them up and put them in that way um there's lots of ways in and out there's um you know lots of different methods to get um text in um I can go screen scrape I can use requests or you uh url lib to suck in text there's lots and lots of ways to uh to get things there's also a great set of tools that he didn't talk about that let me go at github right so um you know get get checked basically lets me um check something into github um and and retrieve things from github um there's another thing for dropbox that's much more of a user interface where I pick the file that I want and I just suck in that one file um yeah there's lots of ways to get things into and out of um github and dropbox and uh and other techniques yeah so this so the question is about remote requests um this is where we start crossing the lines that get apple very nervous so so right now apple doesn't love python anyway because python has got some new momentum that scares them a little bit and they're really trying to get people to swift right they're they're trying to say okay we told you the answer was objective c but we were only kidding the answer is now swift and people are scratching their head about do they really want swift or not um so they're really really trying to use this um this idea that mobile code is a dangerous idea right and I I came from after I worked at apple I worked at sun so I don't believe that mobile code is a bad idea I believe that mobile code with the right security and the right sandboxing and the right understanding is is sort of vital to what to what we need to do in a modern computing platform um but I can tell you that that when we um cross that line of um doing things automatically where we automatically bring executable content into the environment and execute it without the user's authority or oversight or watching applicants really nervous and when the applicants nervous they actually take the app out of the app store right so um that that that has happened and it has happened again very recently so um it's it's a line that that is difficult to cross they they really don't want mobile code that happens without user authorization and physical clicking exact and eval that concept is disabled no exact and eval that all works that all works go for it is there a way to use a version control system in the iOS uh it depends on whether you call github a version control system um no I mean so so so so this is this is not a replacement for your your pc or your windows box or your Linux box um and some of the complex things that you can do and just love on those devices you don't have here um you could probably put something together but is it there today no it's not but join the community and help us out one minute last question yep all right why did you kind of actually question me when you say that uh make the focus for all the barriers and um I from the iOS as a project um it's named kivy yep yep yeah it's actually yep yeah definitely been hearing lately about kivy and and people saying it's it's really cool you can put stuff together really fast with it um pretty interesting platform so take a look um thanks a lot for your time it's been a real pleasure to speak with you