{"_id":"553d394e9660ba0d00569d15","project":"543467200ef9c00800164ecc","category":{"_id":"553d394d9660ba0d00569d08","pages":["553d394e9660ba0d00569d13","553d394e9660ba0d00569d14","553d394e9660ba0d00569d15","553d394e9660ba0d00569d16","553d394e9660ba0d00569d17","553d394e9660ba0d00569d18","553d394e9660ba0d00569d19","553d394e9660ba0d00569d1a","553d394e9660ba0d00569d1b","553d394e9660ba0d00569d1c","553d394e9660ba0d00569d1d","553d394e9660ba0d00569d1e","553d394e9660ba0d00569d1f","553d394e9660ba0d00569d20","553d394e9660ba0d00569d21","553d394e9660ba0d00569d22","553d394e9660ba0d00569d23"],"project":"543467200ef9c00800164ecc","version":"553d394d9660ba0d00569d07","__v":1,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-15T18:00:23.862Z","from_sync":false,"order":0,"slug":"glim","title":"GLIM"},"githubsync":"","user":"543466ea0e8e2b0e00341818","version":{"_id":"553d394d9660ba0d00569d07","project":"543467200ef9c00800164ecc","forked_from":"54bedb2fffb79c320030db1f","__v":1,"createdAt":"2015-04-26T19:15:25.245Z","releaseDate":"2015-04-26T19:15:25.245Z","categories":["553d394d9660ba0d00569d08","553d394d9660ba0d00569d09"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"0.11.2","version":"0.11.2"},"__v":11,"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-10-07T22:20:16.722Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":2,"body":"After we have a working glim app, now it can be further learned what's inside a typical glim app and some configuration tips.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"App Structure\"\n}\n[/block]\n`$ glim new` command creates the following directory structure;\n```\napp\n├── commands.py        => custom command line utilities\n├── config             => configuration sources\n│   └── default.py     => a sample default config\n|   └── development.py => the development environment config\n├── controllers.py     => controller sources\n├── models.py          => model layer sources\n├── routes.py          => application routes source\n├── services.py        => application services source\n├── static             => static folder to hold css,img,js,etc.\n├── start.py           => functions run before the web app starts\n└── storage            => storage folder for logs, sessions, etc.\next                    => ext folder to keep extensions\n```\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Configuration\"\n}\n[/block]\nGlim provides a structure to keep application level constants. `app/config` folder has application level configuration. After creating a sample app, glim automatically creates this folder.\n\nBy default, `app/config` has two files namely `default.py` & `development.py`. The name of these files are mapped to the possible environments to run the app. The default environment is `development`, which is mapped into `development.py`. In this folder, it's highly suggested not to use `default.py`. This file is there because of backup purposes.\n\nThe simplest configuration file would be the following;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# config.py\\nimport os\\nimport glim.paths\\n\\nimport os\\nimport glim.paths\\n\\nconfig = {\\n\\n    # the configurations of extensions\\n    'extensions': {\\n        # 'gredis' : {\\n        #   'default' : {\\n        #       'host' : 'localhost',\\n        #       'port' : '6379',\\n        #       'db'   : 0\\n        #   }\\n        # }\\n    },\\n\\n    # logging configuration, it has a default configuration\\n    # if you don't provide one.\\n    'log' : {\\n\\n        'app' : {\\n          'level': 'info',\\n          'format': '[%(levelname)s] - application : %(message)s',\\n          'colored': True\\n          # 'file' : 'app/storage/logs/app.log'\\n        },\\n\\n        'glim' : {\\n            'level' : 'info',\\n            'format' : '[%(levelname)s] : %(message)s',\\n            'colored': True\\n            # 'file' : 'app/storage/logs/glim.log'\\n        },\\n\\n    },\\n\\n    # the glim.app.App configuration\\n    'app': {\\n        'server': {\\n            'host': '127.0.0.1',\\n            'port': 8080,\\n            'wsgi': 'wsgiref',\\n            'reloader': True,\\n            'debugger': True,\\n            'options': {}\\n        },\\n        'assets': {\\n            'path': glim.paths.ASSET_PATH,\\n            'url': '/assets'\\n        }\\n    }\\n}\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\nMost of these configuration variables have internal default values. So, even if they don't exist, the default variables will be assigned automatically by glim. However, currently, it is required to have at least the keys in the dictionary. Some of the keys and their usages are the following;\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Don't remove the keys, instead, remove the contents of the keys\",\n  \"body\": \"For not re remembering all those keys, it is highly suggested to change & remove the values of the keys but not removing the keys itself. Moreover, glim may require the existence of these keys even it doesn't require the values.\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"extensions\",\n    \"h-0\": \"Key\",\n    \"h-1\": \"Usage\",\n    \"0-1\": \"Dynamic extension loading and keeping the extension configurations with respect to different environments\",\n    \"1-0\": \"log\",\n    \"1-1\": \"Holds configuration for logging level of the environment, the logging format and the file name if provided. There exist a default logging setting if you don't provide one.\",\n    \"2-0\": \"app\",\n    \"2-1\": \"This key holds configuration mosty about the web server. If you are familiar with bottle , you may notice these keys are used by the wsgi of glim. Note that glim serves the static files using /assets url with assets folder.\"\n  },\n  \"cols\": 2,\n  \"rows\": 3\n}\n[/block]\nThe keys can be accessed from the application using the `Config` module. There exists a `Config` instance to access, modify, flush these keys;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"from glim import Config\\n\\n# deeply get using dot \\\".\\\" notation\\nConfig.get('app.server.host')\\n# returns 127.0.0.1\\n\\nConfig.set('app.server.host', 'localhost')\\n# sets app.server.host as localhost\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Use Config.set() function smartly!\",\n  \"body\": \"Although configuration should be readonly, there exists the set() function for setting configuration in runtime. Don't use set() function unless there is an absolute need.\"\n}\n[/block]\n## Adding key/values to config\nYou can add other constants simply by adding a new key to the `config dict`. For instance, if you have a facebook connect in your glim app, you can append the following and have access by the following `Config` function call;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# app/config/<env>.py\\n# append this key inside config\\n{\\n    'facebook': {\\n        'key': 'your-application-key',\\n        'secret': 'your-application-secret'\\n    }\\n}\\n\\n# access these keys by the following;\\nfrom glim import Config\\n\\nConfig.get('facebook.key') # returns the key\\nConfig.get('facebook.secret') # returns the secret\\n\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Environments\"\n}\n[/block]\nAs it is mentioned above, glim has support for multi environment configurations. In glim, each configuration file in `app/config` maps to an environment. By default, the `development` environment is enabled for the app. You can start the app with different environments using the following command;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"glim start --env production\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the example above, glim searches for `app/config/production.py` to load to the `Config` class.\n\n## Adding new environments\nSuppose that you need a testing environment. This environment can easily be generated and started by the following;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"cp app/config/default.py app/config/testing.py\\n\\nglim start --env testing\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]","excerpt":"This page will help you get started with glim. You'll be up and running in a jiffy!","slug":"getting-started","type":"basic","title":"Getting started"}

Getting started

This page will help you get started with glim. You'll be up and running in a jiffy!

After we have a working glim app, now it can be further learned what's inside a typical glim app and some configuration tips. [block:api-header] { "type": "basic", "title": "App Structure" } [/block] `$ glim new` command creates the following directory structure; ``` app ├── commands.py => custom command line utilities ├── config => configuration sources │ └── default.py => a sample default config | └── development.py => the development environment config ├── controllers.py => controller sources ├── models.py => model layer sources ├── routes.py => application routes source ├── services.py => application services source ├── static => static folder to hold css,img,js,etc. ├── start.py => functions run before the web app starts └── storage => storage folder for logs, sessions, etc. ext => ext folder to keep extensions ``` [block:api-header] { "type": "basic", "title": "Configuration" } [/block] Glim provides a structure to keep application level constants. `app/config` folder has application level configuration. After creating a sample app, glim automatically creates this folder. By default, `app/config` has two files namely `default.py` & `development.py`. The name of these files are mapped to the possible environments to run the app. The default environment is `development`, which is mapped into `development.py`. In this folder, it's highly suggested not to use `default.py`. This file is there because of backup purposes. The simplest configuration file would be the following; [block:code] { "codes": [ { "code": "# config.py\nimport os\nimport glim.paths\n\nimport os\nimport glim.paths\n\nconfig = {\n\n # the configurations of extensions\n 'extensions': {\n # 'gredis' : {\n # 'default' : {\n # 'host' : 'localhost',\n # 'port' : '6379',\n # 'db' : 0\n # }\n # }\n },\n\n # logging configuration, it has a default configuration\n # if you don't provide one.\n 'log' : {\n\n 'app' : {\n 'level': 'info',\n 'format': '[%(levelname)s] - application : %(message)s',\n 'colored': True\n # 'file' : 'app/storage/logs/app.log'\n },\n\n 'glim' : {\n 'level' : 'info',\n 'format' : '[%(levelname)s] : %(message)s',\n 'colored': True\n # 'file' : 'app/storage/logs/glim.log'\n },\n\n },\n\n # the glim.app.App configuration\n 'app': {\n 'server': {\n 'host': '127.0.0.1',\n 'port': 8080,\n 'wsgi': 'wsgiref',\n 'reloader': True,\n 'debugger': True,\n 'options': {}\n },\n 'assets': {\n 'path': glim.paths.ASSET_PATH,\n 'url': '/assets'\n }\n }\n}", "language": "python" } ] } [/block] Most of these configuration variables have internal default values. So, even if they don't exist, the default variables will be assigned automatically by glim. However, currently, it is required to have at least the keys in the dictionary. Some of the keys and their usages are the following; [block:callout] { "type": "warning", "title": "Don't remove the keys, instead, remove the contents of the keys", "body": "For not re remembering all those keys, it is highly suggested to change & remove the values of the keys but not removing the keys itself. Moreover, glim may require the existence of these keys even it doesn't require the values." } [/block] [block:parameters] { "data": { "0-0": "extensions", "h-0": "Key", "h-1": "Usage", "0-1": "Dynamic extension loading and keeping the extension configurations with respect to different environments", "1-0": "log", "1-1": "Holds configuration for logging level of the environment, the logging format and the file name if provided. There exist a default logging setting if you don't provide one.", "2-0": "app", "2-1": "This key holds configuration mosty about the web server. If you are familiar with bottle , you may notice these keys are used by the wsgi of glim. Note that glim serves the static files using /assets url with assets folder." }, "cols": 2, "rows": 3 } [/block] The keys can be accessed from the application using the `Config` module. There exists a `Config` instance to access, modify, flush these keys; [block:code] { "codes": [ { "code": "from glim import Config\n\n# deeply get using dot \".\" notation\nConfig.get('app.server.host')\n# returns 127.0.0.1\n\nConfig.set('app.server.host', 'localhost')\n# sets app.server.host as localhost", "language": "python" } ] } [/block] [block:callout] { "type": "warning", "title": "Use Config.set() function smartly!", "body": "Although configuration should be readonly, there exists the set() function for setting configuration in runtime. Don't use set() function unless there is an absolute need." } [/block] ## Adding key/values to config You can add other constants simply by adding a new key to the `config dict`. For instance, if you have a facebook connect in your glim app, you can append the following and have access by the following `Config` function call; [block:code] { "codes": [ { "code": "# app/config/<env>.py\n# append this key inside config\n{\n 'facebook': {\n 'key': 'your-application-key',\n 'secret': 'your-application-secret'\n }\n}\n\n# access these keys by the following;\nfrom glim import Config\n\nConfig.get('facebook.key') # returns the key\nConfig.get('facebook.secret') # returns the secret\n", "language": "python" } ] } [/block] [block:api-header] { "type": "basic", "title": "Environments" } [/block] As it is mentioned above, glim has support for multi environment configurations. In glim, each configuration file in `app/config` maps to an environment. By default, the `development` environment is enabled for the app. You can start the app with different environments using the following command; [block:code] { "codes": [ { "code": "glim start --env production", "language": "shell" } ] } [/block] In the example above, glim searches for `app/config/production.py` to load to the `Config` class. ## Adding new environments Suppose that you need a testing environment. This environment can easily be generated and started by the following; [block:code] { "codes": [ { "code": "cp app/config/default.py app/config/testing.py\n\nglim start --env testing", "language": "shell" } ] } [/block]