From the course: Building RESTful APIs with Flask
Creating a new Flask project in PyCharm
From the course: Building RESTful APIs with Flask
Creating a new Flask project in PyCharm
- [Instructor] To get started we'll open up PyCharm as you can see I've launched it already. Now the feature I'm about to show you is only available in the professional edition of PyCharm. There is a free community version but it doesn't have any tooling or workflows for Flask. It only handles simple Python files and projects. If you don't have access to PyCharm professional you can still use any text editor and you can borrow the project file from the exercise files for this video. We'll create our new project by simply clicking create new project. The first thing I'll want to do is find Flask in the list to the left and now I want to give my project a name, I'm going to stick with the standard PyCharm projects folder and within that I will make one called planetary dash API. We're going to be using a virtual environment with Python 3 for this project, if you're new to Python a virtual environment allows you to create copies of the Python interpreter and tie them to specific projects. This allows you to work with different versions of Python in different projects easily. Using a virtual environment is considered a best practice but it isn't a requirement. For development projects though it makes sense to always create a virtual environment. PyCharm is going to be doing most of this for us, if I twirl down the project interpreter I can see the settings for creating the virtual environment, there are two main options here. Creating a new environment or using an existing environment. We're going to create a new one, and we're going to do it using a tool called VirtualENV. This is the standard way of creating Python virtual environments. If you click the dropdown you can see the other options. The one really most worth mentioning is Conda if you're doing scientific work or deep learning or any of the mathematically intense operations that might benefit from Anaconda you might want to go with Conda on this one. Since we're just making a normal API I'll go ahead and click VirtualENV, next I need to select a location, by default it's going to create a folder called venv within my project folder, I'm okay with that so let's move on to the next setting. Potentially the most important one and that is the base interpreter. This is where you get to select which version of Python you want to use for your project. If you click the dropdown you can see all the versions of Python that are available to you on your computer. Mine is defaulting to Python 3.7 which is what I want to use. If you don't happen to have 3.7 installed, you're probably fine going back as far as 3.4. If you find you need to install a newer version of Python just go to Python.org and download the installer for your operating system. Quit PyCharm, run the installer then come back in to PyCharm and you should see the new version of Python in the list. There's one more section here, if I twirl down next to more settings I can see the templating language settings for my project. Since this is an API project we don't be using any templating language. A templating language is just a way to dynamically generate HTML the same way you would in PHP, Java Server Pages or Active Server Pages in .NET. Our output in our case is purely data in the JSON format so these settings don't matter. Now that I'm happy with all of my settings, I'll click create. PyCharm will go ahead and set up my virtual environment and then build my basic project structure. Don't be surprised if it takes a few minutes to download the packages. So that's it, Flask projects in PyCharm are very simple it generated one file and installed half a dozen third party dependencies. One of the reasons I was drawn to working with Flask in the first place is this simplicity. Other languages like Java and C# allow you to create RESTful APIs but they typically come with a lot more boiler plate and in my case I was using C# a few years ago, the API projects in Visual Studio were bad about installing a bunch of dependencies that I didn't need. I had 1000 files in my project before I'd written a single line of code. We are for the most part in this course, going to be working with only one file.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.