{ "info": { "author": "Daniel Furtado", "author_email": "daniel@dfurtado.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Natural Language :: English", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only" ], "description": "[](https://travis-ci.org/dfurtado/pyterrier)\n[](https://pypi.python.org/pypi/pyterrier)\n\n\n# PyTerrier\n\nThis project has started out of my curiosity to understand how web frameworks work under the hood, to study\nclosely the http module and also the feel that the Python community need to have frameworks written in Python 3, so\nwe can take advantage of all its neat features. PyTerrier is highly inspired by frameworks like Flask, Django and Microsoft's Web API.\n\n## Highlight features\n\n- Written in Python 3.7\n- Favorite conventions over configuration\n- Value simple code\n- Flexible\n- Provide a clean project structure\n\n## Quick start\n\nThe quickest way to get started is to install PyTerrier on a virtual environment and use the PyTerrier CLI to create a\nnew project:\n\n1. Create a new directory for your application\n\n```shell\nmkdir myapp && cd myapp\n```\n\n2. Create a virtual environment (make sure that you have Python 3.6 or greater)\n\n```\npipenv --three\n```\n\n3. Activate the virtual environment\n\n```shell\npipenv shell\n```\n\n3. Install Pyterrier\n\n```shell\npipenv install pyterrier\n```\n\n### Creating your first application\n\nNow that the PyTerrier is installed you can use the CLI to create our first application, execute the command below:\n\n```shell\npyterrier --newapp myapp --currentdir\n```\n\nThe `--newapp` option especify the name of you application, the option `--currentdir` is used when you want the CLI to create the\napplication files in our current directory, without this option the CLI will create a directory with the same name of your application\nand create the files in there.\n\nThat's it, you done!\n\nBy default, the application will run on the port 8000. Just open up your browser and go to http://localhost:8000\n\nTo get a full description of the options available in the Pyterrier CLI you can use the `--help` option like so `pyterrier --help` and you should see the output below:\n\n```text\nUsage: pyterrier [OPTIONS]\n\nOptions:\n --currentdir Create the app on the current directory.\n --newapp NAME Name of the new app.\n --newcontroller NAME Name of the new controller.\n --help Show this message and exit.\n```\n\n## Show me some code!!\n\nPyTerrier favorite conventions over configurations, so the project need to follow a certain structure to work, for instance, a minimum bare bone PyTerrier application would have the following structure:\n\n```text\napp\n\u251c\u2500\u2500 app.py\n\u251c\u2500\u2500 controllers\n\u251c\u2500\u2500 static\n\u2514\u2500\u2500 templates\n```\n\n| Item| Description |\n|:------|:-------------|\n|app| It's the root of the application, obviously it can be any name you like|\n|app.py| This is the application's entry point, there you can initialize the application and register routes|\n|controllers| The `controllers`directory will be the place files containing your actions|\n|static| The `static`directory is where you can place all the static assets of your application. CSS, JavaScript, Images, Fonts...|\n|templates| This is the folder where Pyterrier will lookup for templates to render|\n\n\nA very simple PyTerrier application would look a bit like this:\n\n``` python\nfrom pyterrier import PyTerrier\nfrom pyterrier.http import ViewResult\n\napp = PyTerrier(port=3000)\n\n@app.get('/sayhello')\ndef sayhello(self):\n return ViewResult('index.html', { 'message': 'Hellooooo!' })\n\napp.run()\n\n```\n\nThis code will start a server running on the port 3000 and it will define a function that will be executed when a GET request to `/sayhello` is made.\n\nThe `sayhello` function will return a `ViewResult` which will get a template, the context and render it using the template engine of your choice. By default, PyTerrier uses Jinja2.\n\nLet's have a look how the template looks like.\n\nTo avoid repeating HTML code we have a base file.\n\n``` html\n\n
\n \n \n