{"id":16724849,"url":"https://github.com/rolinh/bottleplate","last_synced_at":"2025-03-21T21:30:59.091Z","repository":{"id":148286160,"uuid":"20328190","full_name":"rolinh/bottleplate","owner":"rolinh","description":"Complete python bottle template for web applications or API servers.","archived":false,"fork":false,"pushed_at":"2017-05-22T16:37:01.000Z","size":26,"stargazers_count":38,"open_issues_count":1,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T05:12:36.984Z","etag":null,"topics":["bottle","mvc","python","template"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rolinh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-30T12:12:43.000Z","updated_at":"2024-05-10T15:09:39.000Z","dependencies_parsed_at":"2023-05-24T14:15:42.182Z","dependency_job_id":null,"html_url":"https://github.com/rolinh/bottleplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolinh%2Fbottleplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolinh%2Fbottleplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolinh%2Fbottleplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolinh%2Fbottleplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rolinh","download_url":"https://codeload.github.com/rolinh/bottleplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874154,"owners_count":20524576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bottle","mvc","python","template"],"created_at":"2024-10-12T22:46:58.606Z","updated_at":"2025-03-21T21:30:59.075Z","avatar_url":"https://github.com/rolinh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BOTTLEPLATE\n\n**bottleplate** is a [bottle](http://bottlepy.org/docs/stable/) template for\n`python` 3.3+ web applications or API servers. The files structure is very\nsimilar to that of a [Ruby on Rails](http://rubyonrails.org/) application and\nthus follows a model-view-controller (MVC) pattern.  It provides a simple way to\nhave development, test and production environments.  The structure for\nfunctional and unit testing is also already in place.  It is very common for\n`bottle` applications to define routes using the `bottle` route decorator.\nHowever, I find it more convenient to have all routes defined in a file. This\ntemplate uses `bottleplate/config/routes.py` for that.  `SQLAlchemy` is used as\nthe object relational mapping (ORM) tool. It supports a broad range of database\nbackends (MySQL, PostgreSQL, SQLite, ...) and is usually the ORM of choice when\nit comes to `python`. `alembic` is used to handle database migrations so it\ntakes care of the changes regarding the database schemas.\n\nSounds interesting? If you still have questions after having read this readme\nfile, feel free to contact me (either by email or IRC at #gwcomputingnet on\nFreenode).\n\nNeed to have a look at a concrete examples? Have a look at\n[pydeo](https://github.com/Rolinh/pydeo) to see a usage of this template for a\nweb application and [devmine-core](https://github.com/DevMine/devmine-core) to\nsee an example usage of this template for an API server.\n\n## WHAT IS INCLUDED ?\n\nNot much actually since this is not a framework but just a template. However, it\nassumes some choices such as:\n\n* [bottle](http://bottlepy.org/docs/stable/), the minimalist `python` web\n  framework\n* [SQLAlchemy](http://www.sqlalchemy.org/) as the ORM of choice\n* [alembic](https://bitbucket.org/zzzeek/alembic) for handling database\n  migrations\n* [invoke](http://invoke.readthedocs.org/) as the task execution tool\n* [nose](https://nose.readthedocs.org) for unit testing\n* [WebTest](http://webtest.readthedocs.org/) for functional testing\n* [pep8](http://pep8.readthedocs.org/) to check source code conformance to pep8\n  style conventions\n* [flake8](http://flake8.pycqa.org) to scan python source code for errors\n\nOf course, nothing is written into stone and you can adapt the template to your\nneeds.\n\n## FILES STRUCTURE AND ORGANIZATION\n\n### ROOT DIRECTORY\n\nThe root directory contains two folders and some files:\n\n* `alembic.ini.sample`: this is a template file for `alembic.ini`. It is copied\n  to `alembic.ini` when `invoke setup` is run.\n* `bottleplate`: this is where lays your bottle application.\n* `env`: this folder is used for the python virtual environment.\n* `requirements.txt`: this file defines the prerequisite packages to run the\n  application.\n* `requirements_dev.txt`: this file defines the prerequisite packages needed to\n  develop the application or contribute to the project.\n* `run.py`: this script is used to run the application.\n* `tasks.py`: this is where you can define tasks. In some ways, this is similar\n  to UNIX Makefiles. \n\n### THE APPLICATION DIRECTORY\n\n* `app`: is used to organize your application contents such as controllers,\n  static assets, models and views.\n* `app/controllers`: this is where lay the application controllers.\n* `app/helpers`: this is where helper classes are defined.\n* `app/models`: this is where the application models are defined, using\n  SQLAlchemy.\n* `app/views`: this is where the HTML template files are. The basic\n  `bottleplate` uses the `SimpleTemplate`, which is a very simple template\n  engine shipped with `bottle` but of course, other template engines such as\n  [Mako](http://www.makotemplates.org/) may be used instead.\n* `app/views/layouts`: this is where you define the base layout templates to be\n  used with views.\n* `config`: the configuration files lay there.\n* `config/environments`: this is where you define the specific environment\n  settings for development, test or production.\n* `config/routes.py`: this is where you define your routes and associate them to\n  the appropriate controllers.\n* `db`: if you use a SQLite database, you will find the database file here. \n  This folder is also used by `alembic` to store the database migration\n  scripts.\n* `lib`: if you need to write libraries, you would place them here.\n* `log`: this is where the log files should go.\n* `test`: this folder is meant to hold the test files.\n* `test/functional`: this is where you write functional tests.\n* `test/unit`: this is where you write unit tests.\n\n## PREDEFINED TASKS\n\nSome tasks are already defined in the `tasks.py` file.\n\n* `set_settings`: this task is used to copy the default configuration file from\n  from the templates. Basically, it copies the `settings-{environment}.py` file\n  to `settings.py` where `{environment}` is one of `development | production |\n  test`.\n  Example:\n  `invoke set_settings --environment=production`\n* `dev`: run the application.\n* `test_func`: run the functional tests.\n* `test_unit`: run the unit tests.\n* `test`: run both the functional and unit tests.\n* `setup`: copy the setting files and alembic sample files from their templates.\n* `pep8`: check source code compliance to PEP8.\n* `flake8`: check source code for errors.\n* `check` run both the `pep8` and `flake8` tasks.\n* `clean`: clean any python generated files and folders.\n* `clean_env`: run the `clean` tasks and reinitializes the python environment.\n* `rename`: this is supposed to be used only once. It rename the `bottleplate`\n  directory and replaces `bottleplate` and `Bottleplate` names in python sources\n  where appropriate. If you provide a name like this one: `my awesome app`,\n  occurences of `bottleplate` will be replaced by `myawesomeapp` and occurences\n  of `Bottleplate` by `MyAwesomeApp`.\n\n## SETTING THE WHOLE THING\n\nMake sure you have `python` 3.3 or above and `virtualenv`. Follow these steps:\n\n* create the virtual environment: `virtualenv -p python3 env`\n* activate the environment: `source env/bin/activate`\n* install the required packages through `pip`:\n  `pip install -r requirements.txt -r requirements_dev.txt`\n\nFrom now on, you also need to choose which web server backend you are willing to\nuse with bottle. Have a look\n[here](http://bottlepy.org/docs/stable/deployment.html#switching-the-server-backend)\nfor the full list of servers supported by `bottle` but keep in mind that not all\nof them are compatible with `python3`.  Let's assume that your choice is\n`cherrypy` (which is the server set by default in this template but you can\neasily change that). Then, what you would do is make sure that in\n`bottleplate/config/environments/(development|production|test).py`, `server` is\nset to `cherrypy`: `server = 'cherrypy'`. Maybe, it is OK to keep the simple\n`wsgiref` server for testing so you would simple set it to this `wsgiref` for\nthe test environment.\nOf course, you then need to install the server backend: `pip install cherrypy`.\n\nNow that you have a web server backend, you also need to choose a database\nbackend. Let's assume that you choose to use `sqlite` as test and\ndevelopment databases and `postgresql` for production. The you need to change\n`db_url` in the respective files like, for instance:\n\n* `development.py`: `db_url = 'sqlite:///bottleplate/db/dev.db'`\n* `production.py`: `db_url = 'postgresql://user:pass@localhost/dbname'`\n* `test.py`: `db_url = 'sqlite:///:memory:'`\n\nOf course, you might need additional packages to support the database backend.\nFor instance, if you use `postgresql`, you need `psycopg2`.\n\nTo use the migration, you also need to provide the appropriate database URL in\nthe `alembic.ini` file. Have a look at\n[alembic documentation](http://alembic.readthedocs.org/) for more information.\n\nOnce all of this is setup, you can rename the template using this command:\n`invoke rename --name='my awesome app name'`.\nOf course, replace the name by the appropriate one. You may want to remove the\ntemplate under views if you are creating an API server.\n\n## RUN IT\n\nConsidering all has been setup, you can run your application using this command:\n\n    python run.py\n\nOr using `invoke`:\n\n    invoke dev\n\nYou can now navigate to `http://localhost:8080` (considering you haven't changed\nthe default port) and see a sample home page.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frolinh%2Fbottleplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frolinh%2Fbottleplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frolinh%2Fbottleplate/lists"}