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.

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

This method will get a list of ‘Tipos de Orgaos’. 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’.
Return type:pandas ‘DataFrame’
odbrasil.legislativo.camara.pandas_parse_only_attributes(xml_list)

This method converts a list of xml elements containing only attributes (without childs) to a pandas DatFrame.

Parameters:xml_list
Return type:pandas DataFrame

Servidores

odbrasil.servidores.scrap

This module implements the methods to extract the information present on on the government site for open data: http://www.portaldatransparencia.gov.br/servidores/index.asp

Note

The methods present in this module are intended to do web scraping of the data from the “Portal da Transparencia”, since the government doesn’t provide n decent REST API for that service yet.


odbrasil.servidores.scrap.get_servidor_id(name)

This function will load the IdServidor parameter from the government site, it will use scraping methods and not a REST API to do that. The name parameter must be unique, otherwise an exception will be raised.

Parameters:name – The servidor name
Return type:The id of the servidor on the government database
odbrasil.servidores.scrap.get_servidor_remuneracao_bruta(servidor_id)

This function will load the month payment for the ‘Servidor’, it will use scraping methods and not a REST API to do that.

Parameters:servidor_id – The servidor id, returned by get_servidor_id()
Return type:The month payment of that ‘Servidor’

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