https://github.com/generoi/finnish-postal-codes
https://github.com/generoi/finnish-postal-codes
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/generoi/finnish-postal-codes
- Owner: generoi
- Created: 2025-12-16T16:52:11.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2026-06-05T05:39:56.000Z (11 days ago)
- Last Synced: 2026-06-05T07:37:25.645Z (11 days ago)
- Language: PHP
- Size: 7 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Finnish Postal Codes
A Composer package containing all Finnish postal codes and city names in Finnish, Swedish, and English. Data is sourced from [posti.fi](https://www.posti.fi).
## Installation
```bash
composer require generoi/finnish-postal-codes
```
## Usage
### Basic Usage
```php
use 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
}
```
### Direct File Access
If you need raw arrays, you can require the PHP files directly:
```php
$fiData = require 'vendor/generoi/finnish-postal-codes/data/php/postcodes-fi.php';
```
## Data Update
To update the postal code data, run:
```bash
composer run fetch
```
Or directly:
```bash
php scripts/fetch.php
```
Exit codes:
- `0` - Success/Updated
- `1` - Error
- `2` - No change (already up to date)
## Data Files
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)
## License
MIT