MongoDB for Developers with Python Transcripts
Chapter: Mapping classes to MongoDB with the ODM MongoEngine
Lecture: Introducing the application skeleton

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Here we are in the github repository for the course, now notice I put the PyMongo play around stuff that we did into a folder called dir 5 PyMongo,
0:10 now, we're over into our MongoEngine section, and there's actually two things here,
0:15 there's a service central starter and then there's a server central; so a lot of times people like to follow along with the code examples
0:21 which I totally encourage, and this one is the way, it when we saved in the repository exactly the way we're about to get started.
0:28 This one we're going to evolve throughout this demo until it becomes sort of the final version,
0:33 so I want to open this in PyCharm, and I want to use a virtual environment to do that,
0:38 so there's a couple of cool tricks I could do to make a life as easy as possible, so here I am in that service central place, and if I do an ls
0:48 even pin files you see there's nothing other than this sort of starter Python ting we'll talk about in a minute.
0:52 So the first thing I want to do is I want to actually set up a virtual environment
0:56 with Python 3s venv, I'll do a dash copies, and I'm going to call .env, and the name .env here is something that PyCharm will look for,
1:04 so if I open this in PyCharm, after doing this it will actually automatically use this virtual environment,
1:10 so that's cool, that'll save me a few clicks. Let's go over here and throw this in PyCharm, now it's going to take it a second, it's sort of looking
1:20 through that virtual directory, let me add the source control. So here's a really simple starter application that we're going to talk about
1:32 but first let's make sure that we have PyMongo installed. So let's just do a quick list, and notice
1:38 we're already automatically using our virtual environment, that's because it's top level the project, and it's named .env
1:46 so PyCharm said cool, we'll use that, I didn't have to do anything that's why I did that first thing in the terminal before open in here.
1:51 So notice we have basically nothing, probably worthwhile to upgrade setup tools,
2:00 some of the things that depends on C completion sometimes a little nicer, if I have that set up, ok so now we can pip install MongoEngine
2:09 and you'll see that also it's going to install PyMongo, depends on 2.7.1. or greater, and it's thinking about PyMongo,
2:16 thinking about MongoEngine, and then we'll be done. Perfect, it also uses six for Python 2, Python 3 compatibility.
2:25 All right, so now we have our system all set up, we have PyMongo installed and here let me just show you this super simple little app,
2:33 there's absolutely no MongoDB stuff going on, so we have this main that is going to print this header,
2:38 very cool, you can see we're going to call our app service central and it's going to do this user loop, and the user loop just says
2:47 here's some actions that you can do, you can add a car, you can list cars and if you look at implementation, all of these are entirely empty,
2:55 here is where the MongoDB stuff is going to be happening, so let's go and run this, notice there's no run configuration over here
3:00 no green button to run, so I can right click on this and say run and it runs and actually let's make this little higher,
3:08 notice that it's running with the Python out of our virtual environment, Python 3, okay, and now here are little header and then here's our user loop,
3:16 it says you can add a car, cool to do add a car, you can list the cars, you can find a car, you perform service,
3:22 right so we just basically have the structure in place and we're going to use this for the rest of this demo,
3:28 and like I said, we're going to be building on this concept of what we create here.

Talk Python's Mastodon Michael Kennedy's Mastodon