Find Brazilian addresses by zipcode, directly from Correios database. No HTML parsers.
Clone or download
Latest commit 2668a7d Mar 19, 2018

Correios CEP

Current available solutions to find Brazilian addresses by zipcode use an HTML form from Correios web site website to perform it, instead of to use a real API.

The old solution works with an HTTP request to the form, followed by parsing HTML result page. The huge problem here is when the Correios web site development team decides to modify some HTML element in the result page, even a layout update, it will break the parser logic for result.

Correios CEP gem solves this problem, retrieving data directly from Correios database.

Correios Logo

Gem Version Build Status Coverage Status Code Climate Dependency Status GitHub license



gem 'correios-cep'

Direct installation

$ gem install correios-cep


require 'correios-cep'

# With "get" instance method
finder =
address = finder.get("54250610")

# With "get" class method
address = Correios::CEP::AddressFinder.get("54250610")

address # =>
  :address => "Rua Fernando Amorim",
  :neighborhood => "Cavaleiro",
  :city => "Jaboatão dos Guararapes",
  :state => "PE",
  :zipcode => "54250610",
  :complement => ""



For default, the timeout for a request to Correios Web Service is 5 seconds. If Correios Web Service does not respond, a Timeout::Error exception will be raised. You can configure this timeout using Correios::CEP module.

Correios::CEP.configure do |config|
  config.request_timeout = 3 # It configures timeout to 3 seconds

HTTP Proxy

If you need to use an HTTP proxy to HTTP requests, configure the HTTP proxy URL on Correios::CEP module.

Correios::CEP.configure do |config|
  config.proxy_url = ""


For default, each request to Correios Web service is logged to STDOUT, with :info log level, using the gem LogMe.

Log example:

I, [2014-02-14T00:10:12.718413 #76361]  INFO -- : [Correios::CEP] Request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="" xmlns:cli="">
  <soapenv:Header />

I, [2014-02-14T00:10:12.969937 #76361]  INFO -- : [Correios::CEP] Response:
HTTP/1.1 200 OK
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="">
    <ns2:consultaCEPResponse xmlns:ns2="">
        <cidade>Jaboatão dos Guararapes</cidade>
        <end>Rua Fernando Amorim</end>

To disable the log and configure other log output, use Correios::CEP module:

Correios::CEP.configure do |config|
  config.log_enabled = false   # It disables the log
  config.logger = Rails.logger # It uses Rails logger

Configuration example

Correios::CEP.configure do |config|
  config.logger = Rails.logger
  config.request_timeout = 3 # seconds


See the changes in each version.



Prodis Logo


Contributing to correios-cep

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Don't forget to rebase with branch master in main project before submit the pull request.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.