{"_id":"56a0bda03697d80d002ac5f9","version":{"_id":"56a0bd9e3697d80d002ac5e7","project":"54774d9af3736008009e9e0e","__v":20,"createdAt":"2016-01-21T11:14:38.131Z","releaseDate":"2016-01-21T11:14:38.131Z","categories":["56a0bd9f3697d80d002ac5e8","56a0bd9f3697d80d002ac5e9","56a0bd9f3697d80d002ac5ea","56a0bd9f3697d80d002ac5eb","56b098a43a5b810d00745e3f","56b098da8f7a4f0d0029dd10","56d5a8ecf612b80b00fb69cd","570989853ab43c0e0072b2d6","571006aa10300c0e007f6133","5735a52431a73b1700887ca0","5744b0529e045c0e00b7a7a2","5744b1d0b56d431700d8a4fb","5744b1fb55d65a0e00b436e1","5744b218f9c7411700ce560e","5744b220f9c7411700ce560f","5744b2259e045c0e00b7a7a7","5744b22cf8b79f0e00de6a2d","5744b23155d65a0e00b436e4","5744b242c758290e00fbc235","5744b2569e045c0e00b7a7a8","5756a3f2bb92962900dafe3d","57ee23e81e42900e0014a42f","581c822c98676e0f00d240ef"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Sockets","version_clean":"1.1.0","version":"1.1"},"user":"54ad5f42921992210075173e","__v":2,"category":{"_id":"56a0bd9f3697d80d002ac5e8","pages":["56a0bda03697d80d002ac5f4","56a0bda03697d80d002ac5f5","56a0bda03697d80d002ac5f6","56a0bda03697d80d002ac5f7","56a0bda03697d80d002ac5f8","56a0bda03697d80d002ac5f9","56a0bda03697d80d002ac5fa","56a0bda03697d80d002ac5fb","56a0bda03697d80d002ac5fc","56a0bda03697d80d002ac5fd","56a0bda03697d80d002ac5fe"],"__v":1,"project":"54774d9af3736008009e9e0e","version":"56a0bd9e3697d80d002ac5e7","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-27T16:46:04.014Z","from_sync":false,"order":8,"slug":"libraries-quick-starts","title":"Libraries Quick Starts"},"parentDoc":null,"project":"54774d9af3736008009e9e0e","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-02-18T01:04:16.305Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"This is just a Getting started section. Here is a full [Python Library Reference](http://syncano.github.io/syncano-python/index.html)\"\n}\n[/block]\nGetting Started with Syncano\n---------------------------------------\n\nThis tutorial will walk you through installing and configuring Syncano, as\nwell as how to use it to make API calls.\n\nThis tutorial assumes you are familiar with Python & that you have a [Syncano account](https://dashboard.syncano.io/#signup).\n\nInstalling Syncano\n------------------------\n\nYou can use ``pip`` to install the latest released version of Syncano:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pip install syncano\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIf you want to install Syncano from the source:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"git clone https://github.com/Syncano/syncano-python.git\\ncd syncano-python\\npython setup.py install\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nUsing Virtual Environments\n------------------------------------\n\nAnother common way to install Syncano is to use a ``virtualenv``, which\nprovides isolated environments. First, install the ``virtualenv`` Python\npackage:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pip install virtualenv\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nNext, create a virtual environment by using the ``virtualenv`` command and\nspecifying where you want the virtualenv to be created (you can specify\nany directory you like, though this example allows for compatibility with\n``virtualenvwrapper``):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mkdir ~/.virtualenvs\\nvirtualenv ~/.virtualenvs/syncano\\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nYou can now activate the virtual environment:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"source ~/.virtualenvs/syncano/bin/activate\\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nNow, any usage of ``python`` or ``pip`` (within the current shell) will default\nto the new, isolated version within your virtualenv.\n\nYou can now install Syncano into this virtual environment:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pip install syncano\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nWhen you are done using Syncano, you can deactivate your virtual environment:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"deactivate\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIf you are creating a lot of virtual environments, [virtualenvwrapper](http://virtualenvwrapper.readthedocs.org/en/latest/) is an excellent tool that lets you easily manage your virtual environments.\n\nMaking Connections\n---------------------------\n\nSyncano provides a number of convenience functions to simplify connecting to our services:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \">>> import syncano\\n>>> connection = syncano.connect(email='YOUR_EMAIL', password='YOUR_PASSWORD')\\n\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n\n\nIf you want to connect directly to a chosen instance you can use the `connect_instance()` function:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \">>> import syncano\\n>>> connection = syncano.connect_instance(instance_name='instance_name', email='YOUR_EMAIL', password='YOUR_PASSWORD')\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n   \n\nIf you have obtained your ``Account Key`` from the website you can omit ``email`` & ``password`` and pass ``Account Key`` directly to connection:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \">>> import syncano\\n>>> connection = syncano.connect(api_key='YOUR_API_KEY')\\n>>> connection = syncano.connect_instance(instance_name='instance_name', api_key='YOUR_API_KEY')\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n\nInteracting with Syncano\n--------------------------------\n\nThe following code demonstrates how to create a new `Instance`\nand add an `ApiKey` to it:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \">>> import syncano\\n>>> connection = syncano.connect(api_key='abcd')\\n>>> instance = connection.instances.create(name='dummy_test', description='test')\\n>>> instance\\n<Instance: dummy_test>\\n\\n>>> api_key = instance.api_keys.create()\\n>>> api_key\\n<ApiKey: 47>\\n>>> api_key.api_key\\nu'aad17f86d41483db7088ad2549ccb87902d60e45'\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\nEach model has a different set of fields and commands. For more information check [available models](http://syncano.github.io/syncano-python/models.html#models).\n\nNext Steps\n---------------\n\nIf you'd like more information on interacting with the Syncano via python library, check out the [interacting tutorial](http://syncano.github.io/syncano-python/interacting.html#interacting) or if you want to know what kind of models are available check out the [available models](http://syncano.github.io/syncano-python/refs/syncano.html#subpackages) list.","excerpt":"Python Library Quick Start Guide","slug":"python","type":"basic","title":"Python"}

Python

Python Library Quick Start Guide

[block:callout] { "type": "info", "body": "This is just a Getting started section. Here is a full [Python Library Reference](http://syncano.github.io/syncano-python/index.html)" } [/block] Getting Started with Syncano --------------------------------------- This tutorial will walk you through installing and configuring Syncano, as well as how to use it to make API calls. This tutorial assumes you are familiar with Python & that you have a [Syncano account](https://dashboard.syncano.io/#signup). Installing Syncano ------------------------ You can use ``pip`` to install the latest released version of Syncano: [block:code] { "codes": [ { "code": "pip install syncano", "language": "shell" } ] } [/block] If you want to install Syncano from the source: [block:code] { "codes": [ { "code": "git clone https://github.com/Syncano/syncano-python.git\ncd syncano-python\npython setup.py install", "language": "shell" } ] } [/block] Using Virtual Environments ------------------------------------ Another common way to install Syncano is to use a ``virtualenv``, which provides isolated environments. First, install the ``virtualenv`` Python package: [block:code] { "codes": [ { "code": "pip install virtualenv", "language": "shell" } ] } [/block] Next, create a virtual environment by using the ``virtualenv`` command and specifying where you want the virtualenv to be created (you can specify any directory you like, though this example allows for compatibility with ``virtualenvwrapper``): [block:code] { "codes": [ { "code": "mkdir ~/.virtualenvs\nvirtualenv ~/.virtualenvs/syncano\n", "language": "shell" } ] } [/block] You can now activate the virtual environment: [block:code] { "codes": [ { "code": "source ~/.virtualenvs/syncano/bin/activate\n", "language": "shell" } ] } [/block] Now, any usage of ``python`` or ``pip`` (within the current shell) will default to the new, isolated version within your virtualenv. You can now install Syncano into this virtual environment: [block:code] { "codes": [ { "code": "pip install syncano", "language": "shell" } ] } [/block] When you are done using Syncano, you can deactivate your virtual environment: [block:code] { "codes": [ { "code": "deactivate", "language": "shell" } ] } [/block] If you are creating a lot of virtual environments, [virtualenvwrapper](http://virtualenvwrapper.readthedocs.org/en/latest/) is an excellent tool that lets you easily manage your virtual environments. Making Connections --------------------------- Syncano provides a number of convenience functions to simplify connecting to our services: [block:code] { "codes": [ { "code": ">>> import syncano\n>>> connection = syncano.connect(email='YOUR_EMAIL', password='YOUR_PASSWORD')\n", "language": "python" } ] } [/block] If you want to connect directly to a chosen instance you can use the `connect_instance()` function: [block:code] { "codes": [ { "code": ">>> import syncano\n>>> connection = syncano.connect_instance(instance_name='instance_name', email='YOUR_EMAIL', password='YOUR_PASSWORD')", "language": "python" } ] } [/block] If you have obtained your ``Account Key`` from the website you can omit ``email`` & ``password`` and pass ``Account Key`` directly to connection: [block:code] { "codes": [ { "code": ">>> import syncano\n>>> connection = syncano.connect(api_key='YOUR_API_KEY')\n>>> connection = syncano.connect_instance(instance_name='instance_name', api_key='YOUR_API_KEY')", "language": "python" } ] } [/block] Interacting with Syncano -------------------------------- The following code demonstrates how to create a new `Instance` and add an `ApiKey` to it: [block:code] { "codes": [ { "code": ">>> import syncano\n>>> connection = syncano.connect(api_key='abcd')\n>>> instance = connection.instances.create(name='dummy_test', description='test')\n>>> instance\n<Instance: dummy_test>\n\n>>> api_key = instance.api_keys.create()\n>>> api_key\n<ApiKey: 47>\n>>> api_key.api_key\nu'aad17f86d41483db7088ad2549ccb87902d60e45'", "language": "python" } ] } [/block] Each model has a different set of fields and commands. For more information check [available models](http://syncano.github.io/syncano-python/models.html#models). Next Steps --------------- If you'd like more information on interacting with the Syncano via python library, check out the [interacting tutorial](http://syncano.github.io/syncano-python/interacting.html#interacting) or if you want to know what kind of models are available check out the [available models](http://syncano.github.io/syncano-python/refs/syncano.html#subpackages) list.