<?xml version="1.0" encoding="utf-8" ?>

<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Jaime Gil de Sagredo</title>
    <link href="http://jaimegildesagredo.github.com/atom.xml" rel="self" />
    <id>jaimegildesagredo.github.com</id>
    <updated>2014-10-06T15:25:04+00:00</updated>

    
    <entry>
        <title>Booby 0.5: Introducing the inspection api</title>
        <link href="http://jaimegildesagredo.github.com/2014/01/04/booby-05-introducing-inspection-api.html"/>
        <updated>2014-01-04T00:00:00+00:00</updated>
        <id>http://jaimegildesagredo.github.com/2014/01/04/booby-05-introducing-inspection-api</id>
        <content type="html">&lt;p&gt;Exactly a year ago the first Booby release &lt;a href=&quot;/2013/01/04/booby-data-modeling-and-validation.html&quot;&gt;was announced&lt;/a&gt;. Today with the release of the &lt;em&gt;0.5.0&lt;/em&gt; version I’m very happy to say that Booby has continued to be developed keeping its &lt;em&gt;simplicity&lt;/em&gt; and &lt;em&gt;isolation&lt;/em&gt; from other libraries and providing a thin and robust &lt;em&gt;abstraction layer&lt;/em&gt; for data modeling and usage.&lt;/p&gt;

&lt;h2 id=&quot;the-path-taken&quot;&gt;The path taken&lt;/h2&gt;

&lt;p&gt;During the &lt;a href=&quot;https://booby.readthedocs.org/en/0.5.0/changes.html&quot;&gt;past two versions&lt;/a&gt; I focused on fixing bugs and taking into account some use cases without adding so much features, and provide a &lt;em&gt;pythonic api&lt;/em&gt; that would not interfere nor create undesirable side effects in the end-user application code.&lt;/p&gt;

&lt;p&gt;The idea is to be as non-intrusive as possible and provide a &lt;em&gt;toolkit&lt;/em&gt; to build your own data models, validators, serializators or wathever you need to work with your data.&lt;/p&gt;

&lt;p&gt;And the first step to achieve this comes with the most important feature of this version and that names this post: the &lt;strong&gt;Inspection api&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;implementing-the-inspection-api&quot;&gt;Implementing the Inspection api&lt;/h2&gt;

&lt;p&gt;With the desire of turning Booby into a toolkit for building &lt;a href=&quot;https://en.wikipedia.org/wiki/Data-driven_programming&quot;&gt;data-driven&lt;/a&gt; applications and libraries arises the need for access some internal data of Booby objects and classes, such as &lt;a href=&quot;https://booby.readthedocs.org/en/0.5.0/models.html&quot;&gt;model fields&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A first approach could have been to add a public attribute (let’s name it &lt;code&gt;fields&lt;/code&gt;) to the &lt;code&gt;Model&lt;/code&gt; class containing the model fields. Several things made me get away from this idea quickly. Some examples are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;What happens if my data &lt;em&gt;model&lt;/em&gt; should have a &lt;em&gt;fields&lt;/em&gt; field?&lt;/li&gt;
  &lt;li&gt;What happens if I want to add more public attributes accessing internal Booby data? I will finish with a base &lt;em&gt;Model&lt;/em&gt; class filled with lots of attributes, so the first problem would become bigger.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That would taken me away from my goal of a &lt;em&gt;thin&lt;/em&gt; and &lt;em&gt;non-intrusive&lt;/em&gt; api, so I decided to look for other people’s approaches for this kind of functionalities. I didn’t need to look far to find two good examples: the &lt;a href=&quot;http://docs.python.org/3.3/library/inspect.html&quot;&gt;Python inspect&lt;/a&gt; and the &lt;a href=&quot;http://docs.sqlalchemy.org/en/rel_0_9/core/inspection.html&quot;&gt;SQLAlchemy inspection&lt;/a&gt; modules.&lt;/p&gt;

&lt;p&gt;I took some ideas from both modules to build the Booby one. From the SQLAlchemy module I took &lt;em&gt;its name&lt;/em&gt; because I thought it would be less likely to collision with the Python module. From the Python module I took &lt;em&gt;its functional api&lt;/em&gt; (although with some changes in the way functions are named) because it seems more explicit than the SQLAlchemy common &lt;code&gt;inspect&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;All this has resulted in the &lt;code&gt;booby.inspection&lt;/code&gt; module, that for now defines the &lt;code&gt;get_fields(model)&lt;/code&gt; and &lt;code&gt;is_model(obj)&lt;/code&gt; functions.&lt;/p&gt;

&lt;p&gt;Take a look to the &lt;a href=&quot;https://booby.readthedocs.org/en/0.5.0/inspection.html&quot;&gt;inspection module documentation&lt;/a&gt; for more information about how these functions work.&lt;/p&gt;

&lt;h2 id=&quot;future&quot;&gt;Future&lt;/h2&gt;

&lt;p&gt;The future of &lt;a href=&quot;https://github.com/jaimegildesagredo/booby&quot;&gt;Booby&lt;/a&gt; is linked with the goals exposed above: build a toolkit to model, validate, serialize and whatever you need to work with your application data, always trying to be the more pythonic and least intrusive as possible.&lt;/p&gt;

&lt;p&gt;Some of the changes I have in mind for the next releases are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Decouple &lt;em&gt;validations&lt;/em&gt; and &lt;em&gt;fields&lt;/em&gt;. As Booby fields are not intented only to validate data I want to extract validations from fields. Of course it will be possible to validate fields, but I want to make it more decoupled.&lt;/li&gt;
  &lt;li&gt;Extract more generic base classes (&lt;code&gt;Object&lt;/code&gt; &amp;lt;- &lt;code&gt;Validator&lt;/code&gt; &amp;lt;- &lt;code&gt;Model&lt;/code&gt;) giving support for a more wide range of use cases.&lt;/li&gt;
  &lt;li&gt;Take into account &lt;em&gt;data serialization/deserialization&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Extend the &lt;code&gt;inspection&lt;/code&gt; api with more functionality.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And finally don’t doubt to share your ideas here or &lt;a href=&quot;https://github.com/jaimegildesagredo/booby/issues&quot;&gt;opening issues&lt;/a&gt; at Github. And of course &lt;a href=&quot;https://pypi.python.org/pypi/booby&quot;&gt;download&lt;/a&gt; and &lt;a href=&quot;https://booby.readthedocs.org/en/0.5.0/&quot;&gt;try Booby&lt;/a&gt;.&lt;/p&gt;

</content>
    </entry>
    
    <entry>
        <title>Booby: data modeling and validation</title>
        <link href="http://jaimegildesagredo.github.com/2013/01/04/booby-data-modeling-and-validation.html"/>
        <updated>2013-01-04T00:00:00+00:00</updated>
        <id>http://jaimegildesagredo.github.com/2013/01/04/booby-data-modeling-and-validation</id>
        <content type="html">&lt;p&gt;Today I’m glad to announce the first public release of &lt;a href=&quot;http://pypi.python.org/pypi/booby/0.2&quot;&gt;Booby&lt;/a&gt;, a standalone data &lt;em&gt;modeling&lt;/em&gt; and &lt;em&gt;validation&lt;/em&gt; library written in Python and licensed under the &lt;a href=&quot;http://www.apache.org/licenses/LICENSE-2.0.html&quot;&gt;Apache2 license&lt;/a&gt;. This is an initial version of the data modeling layer that will be used for defining API models in &lt;a href=&quot;http://jaimegildesagredo.github.com/2012/12/26/a-python-restful-api-consumer.html&quot;&gt;Finch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See the following example to get an idea of what Booby is intended to do.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4449143.js&quot;&gt;
&lt;/script&gt;

&lt;h2 id=&quot;models-should-be-data-source-independent&quot;&gt;Models should be data source independent&lt;/h2&gt;

&lt;p&gt;Although &lt;em&gt;resources definition&lt;/em&gt; is one of the main Finch features, I’ve decided to release it as a separated project to keep these two parts as isolated as possible and that they can evolve independently. In the end, &lt;a href=&quot;http://en.wikipedia.org/wiki/Data_modeling&quot;&gt;data modeling&lt;/a&gt; is a very important point in software design and development, and it should not be dependent of the data sources. Furthermore, the idea is that Finch will be completely independent of the resources definition layer sometime.&lt;/p&gt;

&lt;h2 id=&quot;using-booby&quot;&gt;Using Booby&lt;/h2&gt;

&lt;p&gt;During development I tried to keep Booby very simple for easy integration with other libraries and systems. Currently Booby is under active development and it is not a complete data modeling library yet, and &lt;a href=&quot;https://booby.readthedocs.org&quot;&gt;documentation&lt;/a&gt; isn’t too complete, but I’m going to add new &lt;a href=&quot;https://booby.readthedocs.org/en/latest/fields.html&quot;&gt;field types&lt;/a&gt;, &lt;a href=&quot;https://booby.readthedocs.org/en/latest/validators.html&quot;&gt;validators&lt;/a&gt; and serialization formats.&lt;/p&gt;

&lt;p&gt;By the time, although there is so much work to do, you are encouraged to &lt;a href=&quot;https://booby.readthedocs.org/en/latest/install.html&quot;&gt;install&lt;/a&gt; and &lt;a href=&quot;https://booby.readthedocs.org&quot;&gt;try it&lt;/a&gt;, report issues and contribute your code through &lt;a href=&quot;https://github.com/jaimegildesagredo/booby&quot;&gt;Github&lt;/a&gt;.&lt;/p&gt;

</content>
    </entry>
    
    <entry>
        <title>A python RESTful API consumer</title>
        <link href="http://jaimegildesagredo.github.com/2012/12/26/a-python-restful-api-consumer.html"/>
        <updated>2012-12-26T00:00:00+00:00</updated>
        <id>http://jaimegildesagredo.github.com/2012/12/26/a-python-restful-api-consumer</id>
        <content type="html">&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Application_programming_interface#Web_APIs&quot;&gt;Web APIs&lt;/a&gt;, and more particularly &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_state_transfer&quot;&gt;RESTful&lt;/a&gt; APIs, have become very popular in the last few years by the hand of large sites like Fakebook, Twitter or Github, who give developers the opportunity to extend their services with a wide variety of applications and services.&lt;/p&gt;

&lt;p&gt;This huge growth in the development and use of REST APIs has been mainly because of the ease of consuming data from different services to create applications, tools or whatever you imagine, such as another APIs! on nearly any device, operating system or programming language. And what has made this possible? The answer is the &lt;a href=&quot;http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol&quot;&gt;HTTP protocol&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;consuming-rest-apis&quot;&gt;Consuming REST APIs&lt;/h2&gt;

&lt;p&gt;Right, let me show you how easy is to start playing with, for example, the &lt;a href=&quot;http://developer.github.com/v3/repos/&quot;&gt;Github API&lt;/a&gt;, using Python and the awesome &lt;a href=&quot;http://python-requests.org&quot;&gt;Requests&lt;/a&gt; http library.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4356685.js&quot;&gt;
&lt;/script&gt;

&lt;p&gt;It’s so easy! We only have needed to make a GET request to the user repositories endpoint and wait for an OK response to display a list of repository names and programming languages.&lt;/p&gt;

&lt;p&gt;We also could add a new repository to the list making an authenticated POST request to the repositories endpoint and including some data.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4356841.js&quot;&gt;
&lt;/script&gt;

&lt;p&gt;These two previous examples shown very simple use cases, but serve to show the simplicity of consuming REST APIs.&lt;/p&gt;

&lt;p&gt;But unfortunately, in the real world, client applications tend to become more and more complex and begins to be necessary to write some boilerplate code for stuff like &lt;em&gt;prepare requests&lt;/em&gt;, &lt;em&gt;validate data&lt;/em&gt; and &lt;em&gt;parse responses&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;introducing-finch&quot;&gt;Introducing Finch&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/jaimegildesagredo/finch&quot;&gt;Finch&lt;/a&gt; is an asynchronous RESTful API consumer I’m developing for Python.&lt;/p&gt;

&lt;p&gt;The idea is to develop a general purpose, &lt;a href=&quot;http://en.wikipedia.org/wiki/Asynchronous_I/O&quot;&gt;asynchronous&lt;/a&gt; http API consumer, specially focused on remove all of this boilerplate code and provide a high level abstraction layer on top of any API.&lt;/p&gt;

&lt;h2 id=&quot;metadata-driven-clients&quot;&gt;Metadata driven clients&lt;/h2&gt;

&lt;p&gt;In general, a REST API client can be divided into two different parts: resources definition and http related stuff. This separation let us put http code in a high level abstraction and resources details in application metadata.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Put Abstractions in Code, Details in Metadata” &lt;a href=&quot;http://pragprog.com/the-pragmatic-programmer/extracts/tips&quot;&gt;The Pragmatic Programmer&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See the Finch code example below to understand what I’m talking about.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4358924.js&quot;&gt;
&lt;/script&gt;

&lt;p&gt;Here, we have only described the &lt;code&gt;Repo&lt;/code&gt; model and &lt;code&gt;Repos&lt;/code&gt; collection. All of this code is only &lt;em&gt;metadata&lt;/em&gt;, declaratively defined using Python, that Finch will use to perform all the operations needed to get a list of repositories from Github.&lt;/p&gt;

&lt;p&gt;I think this is really interesting because you can dedicate exclusively to define the peculiarities of the API that you are going to consume and your business logic, and leave Finch to do all the repetitive work.&lt;/p&gt;

&lt;h2 id=&quot;and-do-it-asynchronously&quot;&gt;And do it asynchronously&lt;/h2&gt;

&lt;p&gt;The last example shows you Finch working synchronously. That’s fine when your application does not make an intensive use of API request, like in our example.&lt;/p&gt;

&lt;p&gt;But imagine you have to build a highly scalable service that combines several services behind an unique API. You should not have to wait for each response to perform the next request. Here is where asynchronous programming comes into play.&lt;/p&gt;

&lt;p&gt;To allow asynchronous requests, Finch will be initially built on top of the &lt;a href=&quot;http://www.tornadoweb.org&quot;&gt;Tornado&lt;/a&gt; &lt;a href=&quot;http://www.tornadoweb.org/documentation/httpclient.html#tornado.httpclient.AsyncHTTPClient&quot;&gt;asynchronous HTTP Client&lt;/a&gt;. This way you could do something like &lt;code&gt;repos.all(callback)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see the example where we added a new Github repo, but now using Finch asynchronously.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4363081.js&quot;&gt;
&lt;/script&gt;

&lt;h2 id=&quot;sounds-good-i-want-to-start-using-it&quot;&gt;Sounds good, I want to start using it!&lt;/h2&gt;

&lt;p&gt;Sorry, not yet. Finch is still under active development. Although the examples shown here already work, there are some things I want to finish before release the first public version. For this first release I want to provide at least complete &lt;a href=&quot;http://en.wikipedia.org/wiki/Create,_read,_update_and_delete&quot;&gt;CRUD&lt;/a&gt; support, resources definition, authentication and asynchronous requests. I think I can have this version for the beginning of 2013.&lt;/p&gt;

&lt;p&gt;And finally, if you are interested in the project you can track progress on the &lt;a href=&quot;https://github.com/jaimegildesagredo/finch&quot;&gt;Github repo&lt;/a&gt;, on &lt;a href=&quot;http://feeds.feedburner.com/jaimegildesagredo&quot;&gt;this blog&lt;/a&gt; or through my &lt;a href=&quot;https://twitter.com/jaimegil&quot;&gt;Twitter account&lt;/a&gt;. And of course, I would like to know your thoughts ;)&lt;/p&gt;

</content>
    </entry>
    
</feed>
