The modern and developer centric Python web framework that strives for an actual batteries included developer tool with a lot of out of the box functionality with an extremely extendable architecture. Masonite is perfect for beginner developers getting into their first web applications as well as experienced devs that need to utilize the full potential of Masonite to get their applications done.
Masonite works hard to be fast and easy from install to deployment so developers can go from concept to creation in as quick and efficiently as possible. Use it for your next SaaS! Try it once and you’ll fall in love.
Easily send emails with the Mail Provider and the SMTP and Mailgun drivers.
Send websocket requests from your server with the Broadcast Provider and Pusher and Ably drivers.
IOC container and auto resolving dependency injection.
Service Providers to easily add functionality to the framework.
Extremely simple static files configured and ready to go.
Active Record style ORM called Orator.
An extremely useful command line tool called craft commands.
These, among many other features, are all shipped out of the box and ready to go. Use what you need when you need it.
In order to use Masonite, you’ll need:
If you are running on a Linux flavor, you’ll need the Python dev package and the libssl package. You can download these packages by running:
terminal$ sudo apt-get install python-dev libssl-dev
Or you may need to specify your
terminal$ sudo apt-get install python3.6-dev libssl-dev
terminal# dnf install python-devel openssl-devel
Masonite excels at being simple to install and get going. We use a simple command line tool that will become your best friend. You’ll never want to develop again without it. We call them
We can download our
craft command line tool by just running:
terminal$ pip install masonite-cli
If you already have craft installed, Masonite 2.1 requires
masonite-cli>=2.1.0 so you may have to run with the upgrade flag to.
terminal$ pip install masonite-cli --upgrade
Great! We are now ready to create our first project. We should have the new
craft command. We can check this by running:
This should show a list of command options. If it doesn't then try closing your terminal and reopening it or running it with
sudo if you are on a UNIX machine. We are currently only interested in the
craft new command. To create a new project just run:
terminal$ craft new project_name#Crafting Application ...#Application Created Successfully!#Now just cd into your project and run# $ craft install#to install the project dependencies.#Create Something Amazing!$ cd project_name
This will get the latest Masonite project template and unzip it for you. We just need to go into our new project directory and install the dependencies in our
You can optionally create a virtual environment if you don't want to install all of masonite's dependencies on your systems Python. If you use virtual environments then create your virtual environment by running:
terminal$ python -m venv venv$ source venv/bin/activate
or if you are on Windows:
terminal$ python -m venv venv$ ./venv/Scripts/activate
Now lets install our dependencies. We can do this simply by using a
terminal$ craft install
After install you are ready to create Something Amazing! Masonite folder structure is like this.
. ├── LICENSE ├── README.md ├── app │ ├── User.py │ ├── http │ │ ├── controllers controllers │ │ │ └── WelcomeController.py │ │ └── middleware middleware │ │ ├── AuthenticationMiddleware.py │ │ ├── CsrfMiddleware.py │ │ ├── LoadUserMiddleware.py │ │ └── VerifyEmailMiddleware.py │ └── providers service-providers ├── bootstrap │ ├── cache caching │ └── start.py ├── config │ ├── init.py │ ├── application.py │ ├── auth.py │ ├── broadcast.py │ ├── cache.py │ ├── database.py │ ├── mail.py │ ├── middleware.py │ ├── packages.py │ ├── providers.py │ ├── queue.py │ ├── session.py │ └── storage.py ├── craft ├── databases │ ├── migrations database-migrations │ │ ├── 20180109043202createuserstable.py │ │ └── init.py │ └── seeds │ ├── init.py │ ├── databaseseeder.py │ └── usertable_seeder.py ├── requirements.txt ├── resources │ ├── __init.py │ └── templates │ ├── __init.py │ └── welcome.html ├── routes routing │ └── web.py ├── storage static-files │ ├── compiled │ │ └── style.css │ ├── public │ │ ├── favicon.ico │ │ └── robots.txt │ ├── static │ │ ├── __init.py │ │ └── sass │ │ └── style.scss │ └── uploads │ └── __init.py ├── tests testing │ ├── feature <-- Add tests to your single fetures or functions. │ │ └── test_feature_works.py │ ├── framework │ │ ├── test_file_locations.py │ │ └── test_imports.py │ └── unit <-- Add tests to your unit test. │ └── test_works.py └── wsgi.py
This command is just a wrapper around the
pipcommand. This installs all the required dependencies of Masonite, creates a
.env file for us, generates a new secret key, and puts that secret key in our
.env file. After it’s done we can just run the server by using another
After it’s done we can just run the server by using another
terminal$ craft serve
You can also run the server in auto-reload mode which will rerun the server when file changes are detected:
terminal$ craft serve -r
Congratulations! You’ve setup your first Masonite project! Keep going to learn more about how to use Masonite to build your applications.
The Masonite CLI (also known as craft) will try to find all the commands in your project but may not be able to. In this case you will need to call craft directly using something like:
terminal$ python craft serve -r