Metadata-Version: 2.5
Name: algeria-geo
Version: 1.1.0
Summary: Algeria's administrative divisions: 69 wilayas, 538 dairas and 1,541 communes, with Arabic/French search and historical boundaries.
Project-URL: Homepage, https://github.com/test-bit-sys/algeria-geo
Project-URL: Repository, https://github.com/test-bit-sys/algeria-geo
Project-URL: Issues, https://github.com/test-bit-sys/algeria-geo/issues
Author: Safouane (@safouanedz1)
License: MIT
License-File: LICENSE
License-File: NOTICE
Keywords: administrative-divisions,algeria,arabic,commune,daira,geodata,geography,python,wilaya
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

<a id="top"></a>

<p align="right">
  <strong>English</strong> &nbsp;|&nbsp;
  <a href="./README.ar.md">العربية</a> &nbsp;|&nbsp;
  <a href="./README.fr.md">Français</a>
</p>

<div align="center">

  <a href="https://github.com/test-bit-sys/algeria-geo">
    <img src="assets/logo.png" alt="algeria-geo logo" width="720" style="border-radius: 16px; max-width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,0.3);" />
  </a>

  <br/><br/>

  # 🇩🇿 algeria-geo

  **The definitive, zero-runtime-dependency geospatial & administrative dataset for Algeria.**<br/>
  *69 Wilayas, 538 Dairas, and 1,541 Communes with historical boundary views (48, 58, 69) and cross-script search.*

  <br/>

  [![CI](https://github.com/test-bit-sys/algeria-geo/actions/workflows/ci.yml/badge.svg)](https://github.com/test-bit-sys/algeria-geo/actions/workflows/ci.yml)
  [![PyPI](https://img.shields.io/pypi/v/algeria-geo?logo=pypi&color=blue)](https://pypi.org/project/algeria-geo/)
  [![npm](https://img.shields.io/npm/v/algeria-geo?logo=npm&color=red)](https://www.npmjs.com/package/algeria-geo/)
  [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
  [![Python](https://img.shields.io/badge/python-3.10%2B-3776AB?logo=python&logoColor=white)](https://pypi.org/project/algeria-geo/)
  [![TypeScript](https://img.shields.io/badge/typescript-ready-3178C6?logo=typescript&logoColor=white)](https://www.npmjs.com/package/algeria-geo/)
  [![Runtime Dependencies](https://img.shields.io/badge/runtime%20deps-0-brightgreen.svg)](#features)

  <br/>

  [![Telegram Channel](https://img.shields.io/badge/Telegram_Channel-Join-2CA5E0?logo=telegram&logoColor=white)](https://t.me/+WeiJNOn1gJkzNzFk)
  [![Telegram](https://img.shields.io/badge/Telegram-@safouanedz1-2CA5E0?logo=telegram&logoColor=white)](https://t.me/safouanedz1)
  [![Discord](https://img.shields.io/badge/Discord-bin4ary-5865F2?logo=discord&logoColor=white)](https://discord.com)

</div>

---

## Table of Contents

- [Features](#features)
- [Administrative Coverage](#administrative-coverage)
- [Installation](#installation)
- [Quick Start](#quick-start)
  - [TypeScript / JavaScript](#typescript--javascript)
  - [Python](#python)
- [API Reference](#api-reference)
- [Interactive SVG Map & GeoJSON](#interactive-svg-map--geojson)
- [Historical Eras (48, 58, 69)](#historical-eras-48-58-69)
- [Data Distributions (JSON, CSV, SQL)](#data-distributions)
- [Data Source & Provenance](#data-source--provenance)
- [Building from Source](#building-from-source)
- [Contributing](#contributing)
- [License](#license)

---

## Features

- 🇩🇿 **Complete Official Coverage**: All **69 wilayas** (including the 2026 administrative reform: Wilayas 59–69), **538 dairas**, and **1,541 communes**.
- ⏳ **Historical Boundary Eras**: Query administrative boundaries across **48** (1984), **58** (2019), and **69** (2026) wilaya systems.
- 🔍 **Cross-Script Fuzzy Search**: Intelligent search folding Arabic diacritics/tashkeel, French accents, letter variants, and phonetic transliterations (`Warqla` = `Ouargla` = `ورقلة`).
- ⚡ **Zero Runtime Dependencies**: Pure standard library implementation with instant in-memory $O(1)$ dictionary lookups.
- 📦 **Dual Ecosystem Parity**: Identical feature set, function names, and performance in both **TypeScript** (ESM + CommonJS) and **Python** (Typed).
- 🗺️ **Vector SVG Map & GeoJSON**: Clickable, semantic SVG map with 69 wilayas (`data-code`, `data-name-ar`, `data-name-fr`) and GeoJSON polygons for Leaflet/Mapbox/D3.
- 🗄️ **Multi-Format Exports**: Ready-to-import SQL dumps (PostgreSQL, SQLite, MySQL / MariaDB), minified JSON, hierarchical tree, and UTF-8 CSVs.

---

## Administrative Coverage

| Level | Count | Identifiers | Available Names |
|---|:---:|---|---|
| **Wilayas** (ولاية) | **69** | `01` – `69` (ONS 2-digit) | Arabic, French, ASCII romanized |
| **Dairas** (دائرة) | **538** | `0101` – `6912` (4-digit) | Arabic, French, ASCII romanized |
| **Communes** (بلدية) | **1,541** | `0101` – `6912` (ONS 4-digit) | Arabic, French, ASCII romanized |

> [!NOTE]
> Names are provided in Arabic (`name_ar`) and French (`name_fr`). The `name_en` attribute contains an ASCII-safe representation derived from official romanization. Official 5-digit postal codes (`post_code`) and GPS coordinates (`latitude`, `longitude`) are verified and available across all 1,541 communes. Telephone area codes (`phone_code`) are provided for all 69 wilayas.

---

## Installation

### Node.js / TypeScript

```bash
# npm
npm install algeria-geo

# pnpm
pnpm add algeria-geo

# yarn
yarn add algeria-geo

# bun
bun add algeria-geo
```

### Python

```bash
# pip
pip install algeria-geo

# uv
uv add algeria-geo

# poetry
poetry add algeria-geo
```

---

## Quick Start

### TypeScript / JavaScript

Works seamlessly across Node.js, Bun, Deno, Next.js, Nuxt, Vite, and browser bundlers:

```ts
import {
  getWilaya,
  getDaira,
  getCommune,
  getCommunes,
  getWilayaByPhoneCode,
  getWilayaByCommune,
  search,
  toDropdownOptions,
} from "algeria-geo";

// 1. Direct lookups by code or multilingual name
const alger = getWilaya(16); // or getWilaya("16") or getWilaya("الجزائر")
console.log(alger?.name_fr); // "Alger"
console.log(alger?.communes_count); // 57

// 2. Daira and Commune lookups
const daira = getDaira("0301");
console.log(daira?.name_ar); // "الأغواط"

const commune = getCommune("0319");
console.log(commune?.name_ar); // "أفلو"
console.log(commune?.wilaya_code); // "59" (New wilaya in 2026 reform)

// 3. Reverse lookup (Which wilaya does a commune belong to?)
console.log(getWilayaByCommune("0319", 69)?.name_fr); // "Aflou" (Era 69)
console.log(getWilayaByCommune("0319", 58)?.name_fr); // "Laghouat" (Era 58)

// 4. Telephone area code lookup
console.log(getWilayaByPhoneCode("021")?.name_fr); // "Alger"

// 5. Cross-script fuzzy search
const results = search("Warqla", { limit: 5 });
console.log(results.wilayas[0]?.item.name_ar); // "ورقلة"
console.log(results.wilayas[0]?.score); // 0.85

// 6. UI select dropdown options
const options = toDropdownOptions("ar");
// [{ value: "01", label: "أدرار" }, { value: "02", label: "الشلف" }, ...]
```

### Python

```python
import algeria_geo as geo

# 1. Direct lookups by code or multilingual name
alger = geo.get_wilaya(16)  # accepts int or str: "16", "Alger", "الجزائر"
print(alger.name_ar)         # "الجزائر"
print(alger.communes_count)  # 57

# 2. Daira and Commune lookups
daira = geo.get_daira("0301")
print(daira.name_ar)  # "الأغواط"

commune = geo.get_commune("0319")
print(commune.name_ar)       # "أفلو"
print(commune.wilaya_code)   # "59" (Aflou in era 69)

# 3. Reverse commune lookup across historical eras
print(geo.get_wilaya_by_commune("0319", era=69).name_fr)  # "Aflou"
print(geo.get_wilaya_by_commune("0319", era=58).name_fr)  # "Laghouat"

# 4. Telephone area code lookup
print(geo.get_wilaya_by_phone_code("021").name_fr)  # "Alger"

# 5. Cross-script fuzzy search
res = geo.search("Ouargla")
print(res.wilayas[0].item.name_ar)  # "ورقلة"
print(res.best.score)               # 1.0

# 6. JSON serialization for FastAPI / Django / Flask
import json
print(json.dumps(commune.to_dict(), ensure_ascii=False))

# 7. Dropdown options for web forms
dropdown = geo.to_dropdown_options(lang="fr")
# [{"value": "01", "label": "Adrar"}, {"value": "02", "label": "Chlef"}, ...]
```

---

## API Reference

### Unified Query Functions

| Python API | TypeScript API | Description |
|---|---|---|
| `get_wilaya(id, era=69)` | `getWilaya(id, era = 69)` | Look up wilaya by code (`16`, `"16"`) or name in Ar/Fr/En |
| `get_wilayas(era=69)` | `getWilayas(era = 69)` | List all wilayas active in the given boundary era |
| `get_daira(code)` | `getDaira(code)` | Look up a single daira by its 4-digit code |
| `get_dairas(wilaya_code, era=69)` | `getDairas(wilayaCode, era = 69)` | List all dairas belonging to a wilaya |
| `get_all_dairas(era=69)` | `getAllDairas(era = 69)` | List all dairas across Algeria for an era |
| `get_commune(code)` | `getCommune(code)` | Look up a single commune by its 4-digit ONS code |
| `get_communes(wilaya_code, era=69)`| `getCommunes(wilayaCode, era = 69)`| List all communes belonging to a wilaya |
| `get_all_communes(era=69)` | `getAllCommunes(era = 69)` | List all communes across Algeria for an era |
| `get_communes_by_daira(daira_code)`| `getCommunesByDaira(dairaCode)` | List all communes within a specific daira |
| `get_wilaya_by_commune(code, era=69)`| `getWilayaByCommune(code, era = 69)`| Reverse lookup: find the wilaya of a commune |
| `get_wilaya_by_phone_code(phone)` | `getWilayaByPhoneCode(phone)` | Look up wilaya by phone area code (e.g. `"021"`) |
| `search(query, lang, limit)` | `search(query, langOrOptions, limit)` | Multi-lingual fuzzy search across all divisions |
| `get_postal_code(name, wilaya)` | `getPostalCode(name, wilaya)` | Look up postal code (when populated) |
| `to_dropdown_options(lang, era)` | `toDropdownOptions(lang, era)` | Prepare `{ value, label }` options for HTML selects |
| `get_map_svg(era=69, ...)` | `getMapSvg(options?)` | Generate standalone SVG map of Algeria |
| `get_wilaya_svg_path(code)` | `getWilayaSvgPath(code)` | Return SVG path geometry for a wilaya (`d` attribute) |
| `WILAYA_SVG_PATHS` | `WILAYA_SVG_PATHS` | Dictionary/Record mapping wilaya code to SVG path `d` |

---

## Interactive SVG Map & GeoJSON

`algeria-geo` includes a precision vector map (Web Mercator projection) covering all **69 wilayas**, with matching boundaries and semantic attributes (`id="wilaya-XX"`, `data-code="XX"`, `data-name-ar`, `data-name-fr`, `data-phone-code`, `data-era`, `data-dairas`, `data-communes`).

### Pre-Built Vector Distributions

Located in [`dist/maps/`](dist/maps/):

- [`dist/maps/algeria-69.svg`](dist/maps/algeria-69.svg): Clean, responsive SVG with default styles and hover effects.
- [`dist/maps/algeria-69.min.svg`](dist/maps/algeria-69.min.svg): Minified SVG for production web applications and delivery dashboards.
- [`dist/maps/algeria-69.geojson`](dist/maps/algeria-69.geojson): GeoJSON polygons compatible with Leaflet, Mapbox, D3, and QGIS.

### TypeScript / JavaScript Usage

```typescript
import { getMapSvg, getWilayaSvgPath, WILAYA_SVG_PATHS } from "algeria-geo";
// Subpath import also supported:
// import { getMapSvg } from "algeria-geo/map";

// 1. Generate full SVG string (supports era: 48, 58, 69)
const svg = getMapSvg({ era: 69 });

// 2. Or query path geometry for a wilaya
const algerPath = getWilayaSvgPath(16); // "M5752 253l6-1..."
```

### React / Next.js Component Example

```tsx
import { getWilayas, WILAYA_SVG_PATHS } from "algeria-geo";

export function AlgeriaMap({ onSelect }: { onSelect: (code: string) => void }) {
  const wilayas = getWilayas();

  return (
    <svg viewBox="0 0 10000 9999" width="100%" height="100%">
      {wilayas.map((w) => (
        <path
          key={w.code}
          id={`wilaya-${w.code}`}
          d={WILAYA_SVG_PATHS[w.code]}
          className="fill-slate-200 stroke-white stroke-[1.5] hover:fill-emerald-500 cursor-pointer transition-colors"
          onClick={() => onSelect(w.code)}
        >
          <title>{w.name_ar} - {w.name_fr}</title>
        </path>
      ))}
    </svg>
  );
}
```

### Python Usage

```python
import algeria_geo as geo

# 1. Generate standalone SVG map string
svg_map = geo.get_map_svg(era=69)

# 2. Extract path geometry for any wilaya
alger_d = geo.get_wilaya_svg_path(16)
```

---

## Historical Eras (48, 58, 69)

Algeria's administrative map has evolved through three major legislative reorganizations:

```mermaid
flowchart LR
    A["1984 System (Law 84-09)<br/><b>48 Wilayas</b>"] --> B["2019 System (Law 19-12)<br/><b>58 Wilayas</b>"]
    B --> C["2026 System<br/><b>69 Wilayas</b>"]
```

`algeria-geo` preserves complete historical lineage. By passing `era=48` or `era=58`, queries reflect past administrative boundaries:

```python
# In the 58-wilaya system, Aflou belonged to Laghouat (03)
communes_58 = geo.get_communes("03", era=58)

# In the current 69-wilaya system, Aflou is its own wilaya (59)
communes_69 = geo.get_communes("59", era=69)
```

---
## Star History

<a href="https://www.star-history.com/?repos=test-bit-sys%2Falgeria-geo&type=date&legend=top-left">
 <picture>
   <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=test-bit-sys/algeria-geo&type=date&theme=dark&legend=top-left" />
   <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=test-bit-sys/algeria-geo&type=date&legend=top-left" />
   <img alt="Star History Chart" src="https://api.star-history.com/chart?repos=test-bit-sys/algeria-geo&type=date&legend=top-left" />
 </picture>
</a>
## Data Distributions

Pre-built distribution files are located in the [`dist/`](dist/) folder:

| File | Format | Description |
|---|:---:|---|
| [`dist/wilayas.min.json`](dist/wilayas.min.json) | JSON | Minified array of all 69 wilayas with daira/commune counts |
| [`dist/dairas.min.json`](dist/dairas.min.json) | JSON | Minified array of all 538 dairas with historical wilaya codes |
| [`dist/communes.min.json`](dist/communes.min.json) | JSON | Minified array of all 1,541 communes with lineage |
| [`dist/tree.min.json`](dist/tree.min.json) | JSON | Nested tree: Wilayas ➔ Dairas ➔ Communes |
| [`dist/csv/*.csv`](dist/csv/) | CSV | UTF-8 with BOM CSV exports for Excel and data pipelines |
| [`dist/algeria_geo.sql`](dist/algeria_geo.sql) | SQL | Ready-to-run DDL and INSERT statements for PostgreSQL & SQLite |
| [`dist/algeria_geo.mysql.sql`](dist/algeria_geo.mysql.sql) | SQL | Optimized SQL script for MySQL 8 and MariaDB (`utf8mb4`) |
| [`dist/maps/algeria-69.svg`](dist/maps/algeria-69.svg) | SVG | Vector SVG map with all 69 wilayas and semantic data attributes |
| [`dist/maps/algeria-69.min.svg`](dist/maps/algeria-69.min.svg) | SVG | Minified SVG map for fast frontend loading |
| [`dist/maps/algeria-69.geojson`](dist/maps/algeria-69.geojson) | GeoJSON | Polygons in Web Mercator / WGS84 for Leaflet, Mapbox, D3 & QGIS |

---

## Data Sources & Attributions

The administrative boundaries, nomenclature, postal codes, and coordinates in **algeria-geo** are compiled and verified from official legislative records and trusted open-source geographic datasets:

1. **Administrative Boundaries & Nomenclature:**
   - Transcribed directly from executive decrees and legislative texts published in Algeria's official gazette (*Journal officiel de la République algérienne démocratique et populaire*), referenced from [djazairdev/wilayas](https://github.com/djazairdev/wilayas/tree/0b3b6ab2ac1b1569469285d8fe5e7df18666fcdf).
   - 57 communes belonging to Wilaya 16 (Alger) operate under a special administrative status (circonscriptions administratives) and retain `daira_code: null` in official statistical records.

2. **Postal Codes & Verified Coordinates:**
   - Official 5-digit postal codes and municipality center coordinates are derived from the [GeoAlgeria](https://github.com/yasserstudio/geoalgeria) project by Yasser Studio, licensed under the **MIT License**. Copyright (c) 2026 Yasser Studio.

3. **OpenStreetMap Data (ODbL 1.0):**
   - 323 of the 1,541 commune coordinates are derived from OpenStreetMap administrative relations via GeoAlgeria and are made available under the [Open Database License (ODbL) 1.0](https://opendatacommons.org/licenses/odbl/1-0/): **© OpenStreetMap contributors**.

4. **Vector SVG & GeoJSON Boundaries:**
   - Wilaya boundary geometries and vector coordinates are derived from OpenStreetMap administrative relations via the [Algeria69WilayaMap](https://github.com/chemsallioua/Algeria69WilayaMap) project, licensed under the **MIT License**. Boundaries © OpenStreetMap contributors under ODbL 1.0.

See [NOTICE](NOTICE) and [LICENSE](LICENSE) for full details.

---

## Building from Source

```bash
# 1. Validate canonical data integrity
python scripts/build.py --check

# 2. Build distributions (JSON, CSV, SQL, package files)
python scripts/build.py

# 3. Re-import latest upstream data
python scripts/import_source.py
python scripts/build.py
```

---

## Contributing

Contributions are welcome! Please check [CONTRIBUTING.md](CONTRIBUTING.md) for data citation guidelines, local testing instructions, and pull request requirements.

---

## License & Legal Notices

- **Code & Libraries:** Licensed under the [MIT License](LICENSE). Copyright (c) 2026 test-bit-sys.
- **Data Compilation & Postal Codes:** Derived from [GeoAlgeria](https://github.com/yasserstudio/geoalgeria) under the [MIT License](https://opensource.org/licenses/MIT). Copyright (c) 2025-2026 Yasser's studio (https://yasser.studio).
- **OpenStreetMap Coordinates:** 323 commune center coordinates are derived from OpenStreetMap relations via GeoAlgeria and are made available under the [Open Database License (ODbL) 1.0](https://opendatacommons.org/licenses/odbl/1-0/) (**© OpenStreetMap contributors**), and are not released under CC0.
- **Administrative Nomenclature:** Official administrative divisions and names are transcribed from the Official Gazette of the Republic of Algeria.

See the [NOTICE](NOTICE) file for complete third-party licenses and attribution terms.

<p align="right"><a href="#top">Back to top ↑</a></p>
