API

This part of the documentation covers all the interfaces of odbrasil.

Note

odbrasil usually returns the data extracted as a Pandas DataFrame, to get a better introduction on how to use it, see Pandas documentation.

Legislativo

odbrasil.legislativo.camara

This module implements the methods to extract the information present on on the government site for open data: http://www2.camara.gov.br/transparencia/dados-abertos


class odbrasil.legislativo.camara.Deputados

Bases: odbrasil.legislativo.camara.RESTServiceClient

This class is responsible by accessing, extracting and parsing the data from the Deputados government endpoint.

get_deputados(format='pandas', **params)

This method will get a Deputados list in various formats, use the format parameter to define which parameter you want to parse the data.

Parameters:
  • format – “pandas” or “xml”
  • params – extra parameters will be redirected to Requests
Return type:

the parsed xml or the pandas DataFrame.

class odbrasil.legislativo.camara.Orgaos

Bases: odbrasil.legislativo.camara.RESTServiceClient

This class is responsible by accessing, extracting and parsing the data from the Orgaos government endpoint.

get_orgaos(format='pandas', **params)

This method will get a Orgaos list in various formats, use the format parameter to define which parameter you want to parse the data.

Parameters:
  • format – “pandas” or “xml”
  • params – extra parameters will be redirected to Requests
Return type:

the parsed xml or the pandas DataFrame.

class odbrasil.legislativo.camara.RESTServiceClient

Bases: object

The base class used by other subclasses to retrieve data from the government webservices. If you want to subclass this class, you have to define two class variables on your subclass, called base_url and the expected content_type. See Deputados for reference.

This class is responsible for keeping the common functionality used by the service clients, like using the User-Agent as odbrasil/1.0 for instance.

Note

you shouldn’t use this RESTServiceClient on your application except if you really need to customize the internals of the REST client.

get(service, **params)

This method uses the baseurl parameter and concats the service parameter into it to create the request URL. Any extra param passed to this method by the params parameter will be redirected to the Requests request.

Parameters:
  • service – the service, i.e. ‘ObterDeputados’
  • params – extra parameters to be used by Requests
Return type:

the Requests request response

odbrasil.legislativo.camara.pandas_parse_deputados(xml_deputado_list)

Method used to parse a xml parsed list of deputado elements into a pandas DataFrame.

Parameters:xml_deputado_list – the xml parsed data returned by calling Deputados.get_deputados() with the format as ‘xml’ instead of ‘pandas’.
odbrasil.legislativo.camara.pandas_parse_orgao(xml_orgao_list)

Method used to parse a xml parsed list of orgao elements into a pandas DataFrame.

Parameters:xml_orgao_list – the xml parsed data returned by calling Orgaos.get_orgaos() with the format as ‘xml’ instead of ‘pandas’.

odbrasil is a Python module for retrieving and parsing Brazilian government open data. See the Portal Brasileiro de Dados Abertos for more infromation regarding the open data initiative.

This material is Open Data

Feedback

Feedback is greatly appreciated. If you have any questions or comments, mail me.

Useful Links

Table Of Contents

Related Topics

Fork me on GitHub