PHPackages                             tuxonice/pt-zipcode-finder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. tuxonice/pt-zipcode-finder

ActiveLibrary[Search &amp; Filtering](/categories/search)

tuxonice/pt-zipcode-finder
==========================

Portugal zipcode search package with SQLite database

v1.0.1(8mo ago)00[3 PRs](https://github.com/tuxonice/pt-zipcode-finder/pulls)MITPHPPHP ^8.1CI passing

Since Aug 19Pushed 4mo agoCompare

[ Source](https://github.com/tuxonice/pt-zipcode-finder)[ Packagist](https://packagist.org/packages/tuxonice/pt-zipcode-finder)[ RSS](/packages/tuxonice-pt-zipcode-finder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (6)Used By (0)

Portugal Zipcode Finder
=======================

[](#portugal-zipcode-finder)

[![PHP Tests](https://github.com/tuxonice/pt-zipcode-finder/actions/workflows/php-tests.yml/badge.svg?branch=main)](https://github.com/tuxonice/pt-zipcode-finder/actions/workflows/php-tests.yml)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/8e190638ce329ef719268c96586f2cd225b0c69d03012e47d71da54c3a59edd7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d254532253839254135253230382e312d3737376262343f6c6f676f3d706870)](composer.json)[![Code Style: PSR-12](https://camo.githubusercontent.com/7867b7fa8af6f7a53a0d306d0eaef572eeb8559a1b5224e6342e8931b603c671/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64655f7374796c652d5053522d2d31322d3462616634662e737667)](https://www.php-fig.org/psr/psr-12/)

A PHP package for searching Portugal zipcodes using a SQLite database. This package provides tools to import zipcode data from CSV files and perform searches based on zipcode, locality, or street name.

Features
--------

[](#features)

- SQLite database for efficient storage and querying
- Symfony Console commands for easy interaction
- Import data from standard Portugal zipcode CSV files
- Search by zipcode, locality, or street name
- Detailed results with district and municipality information
- Facade implementation for programmatic usage

Installation
------------

[](#installation)

```
composer require tuxonice/pt-zipcode-finder
```

Usage
-----

[](#usage)

### Get data to import

[](#get-data-to-import)

The zipcode data can be obtained from the [CTT website](https://appserver2.ctt.pt/feapl_2/app/open/postalCodeSearch/postalCodeSearch.jspx). You need register and log in to access the data.

The downloaded file is a zip file containing the following files:

FileDescriptionRename toconcelhos.txtMunicipalities listmunicipalities.csvdistritos.txtDistrics listdistricts.csvtodos\_cp.txtZipcodes listzipcodes.csvleiame.txtReadme fileExtract the files from the zip file and rename them to the expected names.

### Importing Data

[](#importing-data)

Before you can search for zipcodes, you need to import the data from the CSV files:

```
# Import from a CSV directory into a database directory
# Syntax: php bin/zipcode-importer import   [--dbname=zipcodes]

# Example: import CSVs from ./source-dir and create ./data-dir/zipcodes.sqlite
php bin/zipcode-importer import source-dir data-dir --dbname=zipcodes

# Using absolute paths
php bin/zipcode-importer import /abs/path/to/csv /abs/path/to/data --dbname=mydb
```

### Using the ZipcodeFinder Facade

[](#using-the-zipcodefinder-facade)

You can use the ZipcodeFinder facade in your PHP code for programmatic access to the zipcode data:

```
