<p>PYBOSSA is a great framework, however we were lacking a nice command line tool to interact with it.</p> <p>For this reason, after providing several different scripts to create projects, add tasks, etc, etc. I've decided to finally create a <strong>simple</strong> command line tool to master the PYBOSSA API.</p> <h2>pbs - mastering PYBOSSA API</h2> <p>As I wanted to create a powerful but simple tool to manage PYBOSSA projects via the command line, I looked for different solutions: argparse, docopt, etc. From all the available solutions I found <a href="http://click.pocoo.org/">Click</a> from <a href="http://lucumr.pocoo.org/">Armin Ronacher</a> and after trying it I was simply AMAZED.</p> <p><em>Click is really powerful, simple and its feature for nesting commands is incredible.</em></p> <p>Thanks to Click I've managed to develop a command line tool for PYBOSSA in two days, that behaves more or less like <em>git</em> with commands, sub-commands and --help options to make your life much simpler!</p> <h2>Installing pbs</h2> <p>Installing <em>pbs</em> is very simple. Just install it with <strong>pip</strong> with the following command:</p> <p>{% highlight bash %} pip install pybossa-pbs {% endhighlight %}</p> <p>Then all the magic happens <i class="twa twa-wink"></i>.</p> <h2>Configuring pbs</h2> <p>I've designed pbs to be very flexible, so all the options can be passed as arguments, giving you all the flexibility that you could need.</p> <p>One of the key aspects that I love from pbs is the possibility of having a config file for storing my credentials for different PYBOSSA servers. This simplifies my life, reduces the ammount of typing and I don't have to check all the time my API-KEY in the servers that I'm using 😃</p> <p>The config file is very simple. It's just a file named <strong>.pybossa.cfg</strong> that looks something like this:</p> <p>{% highlight python %} [default] server: yourserver apikey: yourkey</p> <p>[anotherserver] server: youranotherserver apikey: youranotherkey {% endhighlight%}</p> <p>By default, pbs will use the <em>default</em> section, but if you want to authenticate against another server, all you've to do is to pass the following command line option: <strong>--credentials anotherserver</strong>. Done!</p> <p>You don't actually need that file, but if you are working a lot with PYBOSSA I would recommend you to create it. It's really amazing.</p> <h2>Creating a project</h2> <p>Now that we've pbs configured all we've to do is to create a project. Creating a project is as simple as always. All you need is a <strong>project.json</strong> with something like this:</p> <p>{% highlight JSON%} { 'name': 'Name of your application', 'short_name': 'theslug', 'description': 'description' } {% endhighlight%}</p> <p>Then, if you run pbs from the same folder where that file has been created, all you've to do for creating a project is running the following command:</p> <p>{% highlight bash %} pbs create_project {% endhighlight%}</p> <p>Two words, and your project is created!</p> <h2>Adding tasks</h2> <p>Now that we've our project available in the server, we can add tasks to it. With pbs I wanted to allow users to import tasks from PYBOSSA servers without having to do nothing special. If you visit a project in <a href="http://crowdcrafting.org">Crowdcrafting</a> you will see that right now PYBOSSA allows you to download tasks as files in two different formats: CSV and JSON.</p> <p>Once you've downloaded one set of tasks from Crowdcrafting, pbs allows you to <strong>re-use</strong> the data, as all the projects are using an open-data license. Cool, right?</p> <p>How do you re-use the tasks's file? If you've downloaded the tasks in CSV format, all you have to do is running the following command:</p> <p>{% highlight bash %} pbs add_tasks --tasks-file file --tasks-type=csv {% endhighlight%}</p> <p>Done! <strong>You've even a progress bar and if you have more than 300 tasks, pbs will auto enable the throttling to respect the PYBOSSA limits of the server.</strong> I love this 😉</p> <h2>Adding the task presenter, long description and tutorial</h2> <p>Now, all we've to do is to add the tutorial, task presenter and long description.</p> <p>For adding those files to the project, you can have those files created in a folder, with the following names:</p> <ul> <li><strong>template.html</strong></li> <li><strong>lon_description.md</strong></li> <li><strong>tutorial.html</strong></li> </ul> <p>If those file names exist where you are running the command, then you don't have to type almost anything, just this command:</p> <p>{% highlight bash %} pbs update_project {% endhighlight%}</p> <p>Done! Quick, fast and simple. If you are testing something new, or if you want to reuse a template from another project, all you've to do is tell it to pbs:</p> <p>{% highlight bash %} pbs update_project --task-template /path/to/template.html {% endhighlight%}</p> <h2>An example</h2> <p>In the following video you can see how quickly you can create a project in Crowdcrafting (or any PYBOSSA server) using pbs with the <a href="https://github.com/PYBOSSA/app-flickrperson/">Flickr Person Finder template</a>.</p> <p>Enjoy!</p> <h3>Installing pbs</h3> <div class="embed-responsive embed-responsive-16by9"> <iframe src='http://player.vimeo.com/video/99921525' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> </div> <h3>Creating a project and adding tasks</h3> <div class="embed-responsive embed-responsive-16by9"> <iframe src='http://player.vimeo.com/video/99921526' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div> <p>PS: I almost forgot to mention it: everything is open source and you can check the source code <a href="https://github.com/PYBOSSA/pbs/">here</a>.</p>