A Composer package containing all Finnish postal codes and city names in Finnish, Swedish, and English. Data is sourced from posti.fi.
composer require generoi/finnish-postal-codesuse FinnishPostalCodes\PostalCodes;
use FinnishPostalCodes\Language;
// Create instance with language
$sv = PostalCodes::sv();
$city = $sv->getCity('00900'); // Returns "HELSINGFORS"
$fi = PostalCodes::fi();
$city = $fi->getCity('00900'); // Returns "HELSINKI"
// Get full record
$record = $fi->getRecord('00900');
echo $record->postcode_fi_name; // "HELSINKI"
echo $record->municipal_name_fi; // "Helsinki"
echo $record->ad_area_fi; // "Helsinki-Uusimaa"
// Check if postal code exists
if ($fi->exists('00900')) {
// ...
}
// Get all postal codes
$allPostcodes = $fi->getAllPostcodes();
// Iterate over all records (memory efficient)
foreach ($fi->getFull() as $postcode => $record) {
// Process each record
}If you need raw arrays, you can require the PHP files directly:
$fiData = require 'vendor/generoi/finnish-postal-codes/data/php/postcodes-fi.php';To update the postal code data, run:
composer run fetchOr directly:
php scripts/fetch.phpExit codes:
0- Success/Updated1- Error2- No change (already up to date)
The package includes data in multiple formats:
- JSON:
data/json/postcodes-{fi|sv|en|full}.json - PHP:
data/php/postcodes-{fi|sv|en|full}.php(can be required directly)
MIT