=============== LIBRARY RULES =============== From library maintainers: - Since 1 October 2026 a Nigerian building's postcode is the 11-character NDAPS code, such as EK-01-A03-FK-01. A six-digit pattern does not match it. - Install ng-postcode from PyPI, crates.io or Maven (io.github.adeniyikayodee:ng-postcode). On npm the library is ng-postcode-js; ng-postcode there is another project. - Parsing returns the error as a value in every language. Check the result's type instead of catching an exception. - Store the compact form (EK01A03FK01) and write the hyphenated form (EK-01-A03-FK-01) in messages. - A well-formed code is not necessarily assigned to a building. Confirm it with a level 1 lookup, which is free. - Never correct a mistyped code and then spend a paid lookup on the guess. Show the suggestion to the user first. - To group or select records by state, LGA, district or area, cut each code to a prefix with truncate (ng_postcode_truncate in SQL). Do not slice the string by hand. - In PostgreSQL use the ng_postcode domain from sql/postgres.sql. In DuckDB a check constraint must use IS NOT DISTINCT FROM, as = lets a malformed code through. - To pass an address between systems, send an address record: a postcode reference with its level, plus country NG. Put only a building-level code in another format's postcode field. ### Install and load DuckDB extension Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Install and load the extension for DuckDB. ```sql INSTALL ng_postcode FROM community; LOAD ng_postcode; ``` -------------------------------- ### Install ng-postcode-js Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Use npm to install the JavaScript package. ```bash npm install ng-postcode-js ``` -------------------------------- ### Install ng-postcode-polars Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Use pip to install the Polars extension. ```bash pip install ng-postcode-polars ``` -------------------------------- ### Create PostgreSQL extension Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Install the package and create the extension in PostgreSQL. ```sql CREATE EXTENSION ng_postcode ``` -------------------------------- ### Install ng-address-resolver Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Use pip to install the address resolver package. ```bash pip install ng-address-resolver ``` -------------------------------- ### Install ng-postcode via pip Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/aliases/ng-postcode-js/README.md Install the Python ng-postcode package from PyPI. ```sh pip install ng-postcode ``` -------------------------------- ### Install ng-address-resolver package Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/aliases/ng-address/README.md Install the ng-address-resolver package. The ng-address alias installs this package without containing its own code. ```sh pip install ng-address-resolver ``` -------------------------------- ### Install extension package Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Unpack the release package for your specific PostgreSQL version at the root of the filesystem. ```sh sudo tar -xzf ng_postcode-0.1.0-pg17-x86_64.tar.gz -C / ``` -------------------------------- ### CLI usage examples Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/agent/README.md Shows how to invoke the CLI with a text address or with latitude/longitude coordinates. The output is JSON with status, code, level, confidence, method, question, and evidence. ```sh ng-address "back of Fabian Hotel, off NTA Road, Ado Ekiti" ng-address "my house" --lat 7.6211 --lng 5.2214 ``` -------------------------------- ### Install ng-postcode-js via npm Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/aliases/ng-postcode-js/README.md Install the JavaScript/TypeScript alias package from npm. This command installs the ng-postcode package for you. ```sh npm install ng-postcode-js ``` -------------------------------- ### Install ng-postcode-polars via pip Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/polars/README.md Install the package using pip. This is the first step before importing the library in Python. ```sh pip install ng-postcode-polars ``` -------------------------------- ### Install ng-postcode for Rust Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Use cargo to add the crate to your Rust project. ```bash cargo add ng-postcode ``` -------------------------------- ### Python async usage Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/agent/README.md Shows how to use the Resolver class asynchronously. Requires a NIPOST client, parser, and geocoder. The core needs no model; install the 'claude' extra for Claude-based parsing. ```python from ng_address import Resolver result = await Resolver(nipost=..., parser=..., geocoder=...).resolve("...") ``` -------------------------------- ### Client.send Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Sends a request using the synchronous client. The example shows creating a client with an API key and sending a lookup request with level 1. ```APIDOC ## Client.send ### Description Sends a request using the synchronous client. Returns the typed response, an ApiError, or a TransportError. ### Method send ### Parameters - **request** (Request) - Required - The request to send. ### Returns - **typed response** - The typed response. - **ApiError** - For example 'auth_required' or 'insufficient_credits'. - **TransportError** - A transport error. ### Example ```python from ng_postcode.client import Client from ng_postcode.api import lookup with Client(api_key="nipost_live_...") as client: found = client.send(lookup(code, level=1)) ``` ``` -------------------------------- ### Example CSV output format Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md The resulting CSV file includes the original data plus columns for compact codes, status, suggestions, and error messages. ```text id,postcode,postcode_compact,postcode_status,postcode_suggestion,postcode_error 1,ek 01 a03 fk 01,EK01A03FK01,valid,, 2,EK-O1-A03-FK-01,,suggested,EK-01-A03-FK-01,invalid lga segment 3,360001,,invalid,,"expected 11 letters and digits, found 6" 4,,,empty,, ``` -------------------------------- ### CREATE EXTENSION ng_postcode Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Installs the ng_postcode extension into the current database. This must be run before using any of the extension's types or functions. ```APIDOC ## CREATE EXTENSION ng_postcode ### Description Installs the ng_postcode extension into the current database. This must be run before using any of the extension's types or functions. ### Method CREATE EXTENSION ### Endpoint N/A (SQL statement) ### Parameters None ### Request Example ```sql CREATE EXTENSION ng_postcode; ``` ### Response No direct response; the extension is installed. ``` -------------------------------- ### Store and check postcodes Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Example of creating a table with a postcode column and performing insertion and selection operations. ```sql CREATE TABLE customers ( id bigint PRIMARY KEY, postcode ng_postcode -- refuses anything that is not a compact code ); INSERT INTO customers VALUES (1, ng_postcode_parse('ek 01 a03 fk 01')); SELECT postcode, ng_postcode_format(postcode) FROM customers; -- EK01A03FK01 | EK-01-A03-FK-01 ``` -------------------------------- ### Group by postcode segments Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Example of grouping customers by a specific postcode segment, such as a district. ```sql SELECT ng_postcode_format(ng_postcode_truncate(postcode, 'district')) AS district, count(*) FROM customers GROUP BY 1; -- EK-01-A03 | 1 ``` -------------------------------- ### ng_postcode_within Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Checks whether a code starts with the given prefix. ```APIDOC ## ng_postcode_within(code, prefix) ### Description Returns whether the given code starts with the given prefix. ### Function Signature ng_postcode_within(text, text) -> boolean ### Parameters - **code** (text) - Required - The postcode to check. - **prefix** (text) - Required - The prefix to test against. ### Return Value - **boolean** - True if the code starts with the prefix, false otherwise. ### Example ```sql SELECT ng_postcode_within('EK01A03FK01', 'EK01A03'); -- true ``` ``` -------------------------------- ### ng_postcode_version() Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Returns the version of the installed ng_postcode extension. This is useful for debugging and compatibility checks. ```APIDOC ## ng_postcode_version() ### Description Returns the version of the installed ng_postcode extension. This is useful for debugging and compatibility checks. ### Method Function ### Endpoint ng_postcode_version() ### Parameters None ### Request Example ```sql SELECT ng_postcode_version(); ``` ### Response Returns the version string of the extension. ``` -------------------------------- ### Select by district range Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Example of selecting customers within a specific district using a range comparison to utilize database indexes. ```sql SELECT * FROM customers WHERE postcode >= 'EK01A03' AND postcode < 'EK01A03' || '~'; ``` -------------------------------- ### parse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Parses a postcode string into a Postcode object. The example shows parsing 'FC-03-B06-AG-12' and asserting the result is a Postcode instance. ```APIDOC ## parse ### Description Parses a postcode string into a Postcode object. ### Method parse ### Parameters - **code** (str) - Required - The postcode string to parse. ### Returns - **Postcode** - The parsed postcode object. ### Example ```python from ng_postcode import parse code = parse("FC-03-B06-AG-12") assert isinstance(code, Postcode) ``` ``` -------------------------------- ### Group by district using ng.truncate and ng.format Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/polars/README.md This example shows how to group a DataFrame by district using the `.ng.truncate("district")` and `.ng.format()` expressions. The output shows the count of postcodes per district, with invalid codes grouped under null. ```python by_district = frame.group_by( pl.col("postcode").ng.truncate("district").ng.format().alias("district") ).len() # EK-01-A03 2 # LA-11-W06 1 # null 1 ``` -------------------------------- ### Parse and validate postcodes with ng namespace Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/polars/README.md Importing the package adds an `ng` namespace to every Polars expression. The example creates a DataFrame with sample postcodes and uses `.ng.parse()` and `.ng.is_valid()` to extract the compact code and check validity. Invalid codes become null. ```python import polars as pl import ng_postcode_polars # noqa: F401 frame = pl.DataFrame({"postcode": ["ek 01 a03 fk 01", "EK-01-A03-ZZ-14", "la11w06tc10", "100001"]}) print( frame.with_columns( code=pl.col("postcode").ng.parse(), ok=pl.col("postcode").ng.is_valid(), ) ) # postcode code ok # ek 01 a03 fk 01 EK01A03FK01 true # EK-01-A03-ZZ-14 EK01A03ZZ14 true # la11w06tc10 LA11W06TC10 true # 100001 null false ``` -------------------------------- ### ng_postcode_within(code, prefix) and code <@ prefix Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Tests whether a postcode starts with a given prefix. This is used to check if a code belongs to a particular area. The operator <@ is a shorthand for the function. ```APIDOC ## ng_postcode_within(code, prefix) and code <@ prefix ### Description Tests whether a postcode starts with a given prefix. This is used to check if a code belongs to a particular area. The operator <@ is a shorthand for the function. ### Method Function / Operator ### Endpoint ng_postcode_within(code, prefix) or code <@ prefix ### Parameters - **code** (ng_postcode) - Required - The postcode to test. - **prefix** (ng_postcode_prefix) - Required - The prefix to check against. ### Request Example ```sql SELECT ng_postcode_within(ng_postcode_parse('EK01A03FK01'), ng_postcode_prefix_parse('EK01A03')); -- or SELECT ng_postcode_parse('EK01A03FK01') <@ ng_postcode_prefix_parse('EK01A03'); ``` ### Response Returns boolean true if the code starts with the prefix, false otherwise. ``` -------------------------------- ### Parse a postcode with ng_postcode.parse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Parses a postcode string (hyphenated, spaced, or compact) and returns a Postcode object or an error value. The example shows matching on Postcode and printing its canonical, compact, spaced forms and prefix. ```python from ng_postcode import Postcode, Segment, parse match parse("ek 01 a03 fk 01"): case Postcode() as code: print(code) # EK-01-A03-FK-01 print(code.compact) # EK01A03FK01, store this print(code.spaced) # EK 01 A03 FK 01 print(code.prefix(Segment.AREA)) # EK-01-A03-FK case error: print(error) # e.g. "invalid lga segment" ``` -------------------------------- ### Build MCPB Bundle Command Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/mcp/README.md Command to build the MCPB manifest for clients that support .mcpb files. ```bash npx @anthropic-ai/mcpb pack mcp/bundle ng-postcode.mcpb ``` -------------------------------- ### Run tests for all project components Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/README.md Commands to execute test suites for Rust, Python, MCP, agent, JavaScript, and Java components. ```sh cargo test --all-features # Rust cd python && uv run --group dev pytest # Python library cd mcp && uv run --group dev pytest # MCP server cd agent && uv run --group dev pytest # resolver cd js && npm ci && npm test # JavaScript library and Node MCP server cd java && ./mvnw verify # Java libraries ``` -------------------------------- ### Enable extension in database Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Run this command within your PostgreSQL database to enable the extension. ```sql CREATE EXTENSION ng_postcode; ``` -------------------------------- ### Run ng-postcode-mcp Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Run the MCP server using uvx or npx. ```bash uvx ng-postcode-mcp ``` ```bash npx -y ng-postcode-mcp ``` -------------------------------- ### Perform a postcode lookup with Client Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Demonstrates parsing a postcode string and using the Client to perform a level 1 lookup. It includes error handling for ApiError and TransportError using pattern matching. ```python from ng_postcode import Postcode, parse from ng_postcode.api import ApiError, lookup from ng_postcode.client import Client, TransportError code = parse("FC-03-B06-AG-12") assert isinstance(code, Postcode) with Client(api_key="nipost_live_...") as client: found = client.send(lookup(code, level=1)) match found: case ApiError() | TransportError(): print(found) # e.g. "invalid_api_key (401): ..." case _: print(found.valid, found.status) # True valid ``` -------------------------------- ### Configure MCP server settings Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-mcp/README.md Add this configuration to your MCP client settings to run the server via npx. Requires Node 22.12 or later and an optional NIPOST API key. ```json { "mcpServers": { "ng-postcode": { "command": "npx", "args": ["-y", "ng-postcode-mcp"], "env": { "NG_POSTCODE_API_KEY": "nipost_live_..." } } } } ``` -------------------------------- ### Publish ng-address alias package Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/aliases/README.md Publishes the ng-address alias package. Run from the repository root; this command builds and publishes the package using uv. ```sh cd aliases/ng-address && uv build && uv publish ``` -------------------------------- ### Load SQL scripts via CLI Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Commands to load the postcode SQL scripts into PostgreSQL and DuckDB environments. ```sh psql -f sql/postgres.sql # PostgreSQL, tested on 14 and 17 duckdb my.db < sql/duckdb.sql # DuckDB, tested on 1.5 ``` -------------------------------- ### Run ng-postcode-mcp via HTTP or Docker Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/mcp/README.md Commands to execute the server using the HTTP transport or by building and running a Docker container from the repository root. ```sh NG_POSTCODE_TRANSPORT=http uvx ng-postcode-mcp # http://127.0.0.1:8000/mcp docker build -t ng-postcode-mcp . && docker run --rm -i ng-postcode-mcp # from the repository root ``` -------------------------------- ### Add ng-postcode with client feature Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/CRATE.md Command to add the crate with the `client` feature enabled, which provides a blocking HTTP client built on `ureq`. ```sh cargo add ng-postcode --features client ``` -------------------------------- ### Configure MCP server for AI clients Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/index.md Add this configuration to your MCP client settings to enable the ng-postcode server. Replace the environment variable with your actual NIPOST API key. ```json { "mcpServers": { "ng-postcode": { "command": "uvx", "args": ["ng-postcode-mcp"], "env": { "NG_POSTCODE_API_KEY": "nipost_live_..." } } } } ``` -------------------------------- ### ng_postcode_version Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Returns the version of the loaded SQL file. ```APIDOC ## ng_postcode_version() ### Description Returns the version of the ng-postcode SQL file that was loaded. ### Function Signature ng_postcode_version() -> text ### Parameters None ### Return Value - **text** - The version string of the loaded file. ### Example ```sql SELECT ng_postcode_version(); -- '1.0.0' ``` ``` -------------------------------- ### fromSegments Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-js/README.md Assembles a postcode from its parts, zero-filling the LGA and unit segments. ```APIDOC ## fromSegments ### Description Assembles a postcode from its parts, zero-filling the LGA and unit segments. ### Method fromSegments ### Signature fromSegments(segments: ...) => Postcode ### Parameters - **segments** - Required - The parts of the postcode (state, LGA, district, area, unit). ### Returns - **Postcode** - The assembled Postcode instance. ### Example ```ts import { fromSegments } from "ng-postcode-js"; const code = fromSegments("EK", "01", "A03", "FK", "01"); ``` ``` -------------------------------- ### Convert CSV file with CLI Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/llms.txt Use the CLI tool to process a CSV file and add postcode validation data. ```bash ng-postcode --column postcode customers.csv --out checked.csv ``` -------------------------------- ### Perform API Lookup Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-js/README.md Use the Client class and lookup function to verify postcodes against the NIPOST API. Requires an API key from the NIPOST developer dashboard. ```ts import { Postcode, parse } from "ng-postcode-js"; import { ApiError, lookup } from "ng-postcode-js/api"; import { Client, TransportError } from "ng-postcode-js/client"; const code = parse("FC-03-B06-AG-12"); if (!(code instanceof Postcode)) throw new Error(String(code)); const client = new Client(process.env.NG_POSTCODE_API_KEY ?? ""); const found = await client.send(lookup(code, 1)); if (found instanceof ApiError || found instanceof TransportError) { console.error(String(found)); // e.g. "invalid_api_key (401): ..." } else { console.log(found.valid, found.status); // true valid } ``` -------------------------------- ### .ng.format() Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/polars/README.md Formats a code or a prefix into its hyphenated form (e.g., 'EK-01-A03'). ```APIDOC ## .ng.format() ### Description Formats a code or a prefix into its hyphenated form (e.g., 'EK-01-A03'). ### Method Expression ### Endpoint `pl.col("postcode").ng.format()` ### Returns - **String** - The hyphenated form of the code or prefix. ### Example ```python pl.col("postcode").ng.format() ``` ``` -------------------------------- ### Use ng-postcode in PostgreSQL Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/README.md Demonstrates creating a table with a custom ng_postcode type and using parsing/formatting functions. ```sql CREATE TABLE customers ( id bigint PRIMARY KEY, postcode ng_postcode -- refuses anything that is not a compact code ); INSERT INTO customers VALUES (1, ng_postcode_parse('ek 01 a03 fk 01')); SELECT ng_postcode_format(ng_postcode_truncate(postcode, 'district')) AS district, count(*) FROM customers GROUP BY 1; -- EK-01-A03 | 1 ``` -------------------------------- ### autocomplete Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-js/README.md Creates a Request for autocomplete suggestions. Throws RangeError if the input is empty. ```APIDOC ## autocomplete ### Description Creates a Request for autocomplete suggestions. Throws RangeError if the input is empty. ### Method autocomplete ### Signature autocomplete(input: string) => Request ### Parameters - **input** (string) - Required - The partial postcode or address to autocomplete. ### Returns - **Request** - A plain Request object. ### Throws - **RangeError** - If input is empty. ### Example ```ts import { autocomplete } from "ng-postcode-js/api"; const request = autocomplete("EK-01"); ``` ``` -------------------------------- ### Index and query by district Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Create an index on the truncated postcode to optimize district-based queries. ```sql CREATE INDEX ON customers (ng_postcode_truncate(postcode, 'district')); SELECT * FROM customers WHERE ng_postcode_truncate(postcode, 'district') = 'EK01A03'; ``` -------------------------------- ### Parse and format a postcode offline Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/CRATE.md Parses a postcode string with hyphens, spaces, or case variations, then demonstrates canonical, compact, and spaced formatting, plus access to state and prefix segments. Requires the default features. ```rust use ng_postcode::{ParseError, Postcode, Segment}; fn main() -> Result<(), ParseError> { // Hyphens, spaces and case are all accepted. let code: Postcode = "ek 01 a03 fk 01".parse()?; assert_eq!(code.to_string(), "EK-01-A03-FK-01"); // canonical assert_eq!(code.as_str(), "EK01A03FK01"); // compact, for storage assert_eq!(code.to_spaced(), "EK 01 A03 FK 01"); // for display assert_eq!(code.state(), "EK"); assert_eq!(code.prefix(Segment::Area), "EK-01-A03-FK"); Ok(()) } ``` -------------------------------- ### Define table and insert data Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Create a table using the ng_postcode type and insert codes in various formats. ```sql CREATE TABLE customers ( id bigint PRIMARY KEY, postcode ng_postcode ); INSERT INTO customers VALUES (1, 'ek 01 a03 fk 01'), (2, 'EK-01-A03-ZZ-14'); SELECT postcode, ng_postcode_format(postcode) FROM customers; -- EK01A03FK01 | EK-01-A03-FK-01 -- EK01A03ZZ14 | EK-01-A03-ZZ-14 ``` -------------------------------- ### .ng.parse_prefix() Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/polars/README.md Parses a postcode string into its compact prefix (e.g., 'EK01A03') or returns null if invalid. ```APIDOC ## .ng.parse_prefix() ### Description Parses a postcode string into its compact prefix (e.g., 'EK01A03') or returns null if invalid. ### Method Expression ### Endpoint `pl.col("postcode").ng.parse_prefix()` ### Returns - **String** - The compact prefix (e.g., `EK01A03`) or null if invalid. ### Example ```python pl.col("postcode").ng.parse_prefix() ``` ``` -------------------------------- ### Look up a postcode via the API client Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/CRATE.md Creates a blocking client using the `NG_POSTCODE_API_KEY` environment variable and sends a lookup request for a parsed postcode, printing the administrative address. Requires the `client` feature and a valid API key. ```rust use ng_postcode::{api, client::Client}; fn main() -> Result<(), Box> { let client = Client::new(std::env::var("NG_POSTCODE_API_KEY")?); let found = client.send(&api::lookup("FC-03-B06-AG-12".parse()?, 2)?)?; println!("{:?}", found.administrative_address); Ok(()) } ``` -------------------------------- ### Perform API postcode lookup Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Use the Client class to send API requests and handle the Result object, which distinguishes between successful lookups and failures. ```java import io.github.adeniyikayodee.ngpostcode.Postcode; import io.github.adeniyikayodee.ngpostcode.api.Api; import io.github.adeniyikayodee.ngpostcode.api.Client; import io.github.adeniyikayodee.ngpostcode.api.Lookup; import io.github.adeniyikayodee.ngpostcode.api.Result; var client = new Client(System.getenv("NG_POSTCODE_API_KEY")); Result found = client.send(Api.lookup(new Postcode("FC03B06AG12"), 1)); if (found instanceof Result.Ok ok) { System.out.println(ok.value().valid() + " " + ok.value().status()); // true valid } else if (found instanceof Result.Failed failed) { System.err.println(failed.failure()); // e.g. "invalid_api_key (401): ..." } ``` -------------------------------- ### Api.autocomplete Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Creates an autocomplete request for postcode suggestions. ```APIDOC ## Api.autocomplete ### Description Creates an autocomplete request for postcode suggestions. ### Method autocomplete ### Parameters - **query** (String) - Required - The partial postcode or address to autocomplete. ### Returns - **Request** - A request object that can be sent via a Client or decoded with Api.decode. ### Throws - **IllegalArgumentException** - If the query is blank. ### Example ```java // Example usage not provided in source. ``` ``` -------------------------------- ### Confirm a postcode exists with Rust API client Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/index.md Creates a client with an API key from the NG_POSTCODE_API_KEY environment variable and sends a lookup request. Requires the client feature. Level 1 confirms assignment; higher levels return address details and consume credits. ```rust use ng_postcode::{api, client::Client}; // features = ["client"] let client = Client::new(std::env::var("NG_POSTCODE_API_KEY")?); let found = client.send(&api::lookup("FC-03-B06-AG-12".parse()?, 1)?)?; ``` -------------------------------- ### Postcode.fromSegments Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Assembles a postcode from its parts, zero-filling the LGA and unit segments. ```APIDOC ## Postcode.fromSegments ### Description Assembles a postcode from its parts, zero-filling the LGA and unit segments. ### Method fromSegments ### Parameters - **segments** (Segment...) - Required - The segments of the postcode. ### Returns - **Postcode** - The assembled postcode. ### Example ```java // Example usage not provided in source. ``` ``` -------------------------------- ### Client.send Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-js/README.md Sends a request to the postcode.gov.ng API. Returns a typed result or an ApiError/TransportError. ```APIDOC ## Client.send ### Description Sends a request to the postcode.gov.ng API. Returns a typed result or an ApiError/TransportError. ### Method send ### Signature send(request: Request) => Promise ### Parameters - **request** (Request) - Required - The request to send, typically created by lookup, autocomplete, reverse, or nearby. ### Returns - **Result** - On success, a typed result object. - **ApiError** - On API error, an ApiError instance. - **TransportError** - On transport error, a TransportError instance. ### Example ```ts import { Client, TransportError } from "ng-postcode-js/client"; import { ApiError, lookup } from "ng-postcode-js/api"; import { Postcode, parse } from "ng-postcode-js"; const code = parse("FC-03-B06-AG-12"); if (!(code instanceof Postcode)) throw new Error(String(code)); const client = new Client(process.env.NG_POSTCODE_API_KEY ?? ""); const found = await client.send(lookup(code, 1)); if (found instanceof ApiError || found instanceof TransportError) { console.error(String(found)); // e.g. "invalid_api_key (401): ..." } else { console.log(found.valid, found.status); // true valid } ``` ``` -------------------------------- ### Client.send(Api.lookup(...)) Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Sends a lookup request to the postcode.gov.ng API and returns a Result containing the lookup response or a failure. ```APIDOC ## Client.send(Api.lookup(...)) ### Description Sends a lookup request to the postcode.gov.ng API and returns a Result containing the lookup response or a failure. ### Method send ### Parameters - **request** (Request) - Required - The request to send, typically created via Api.lookup. ### Returns - **Result** - A Result that is either Ok with the Lookup value or Failed with a failure description. ### Example ```java var client = new Client(System.getenv("NG_POSTCODE_API_KEY")); Result found = client.send(Api.lookup(new Postcode("FC03B06AG12"), 1)); if (found instanceof Result.Ok ok) { System.out.println(ok.value().valid() + " " + ok.value().status()); // true valid } else if (found instanceof Result.Failed failed) { System.err.println(failed.failure()); // e.g. "invalid_api_key (401): ..." } ``` ``` -------------------------------- ### Group by district in SQL Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/group-by-place.md Uses SQL functions to truncate postcodes to the district level and group by the resulting prefix. ```sql SELECT ng_postcode_format(ng_postcode_truncate(postcode, 'district')) AS district, count(*) FROM customers GROUP BY 1; ``` -------------------------------- ### reverse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-js/README.md Creates a Request for reverse geocoding. Throws RangeError if the coordinate is not finite. ```APIDOC ## reverse ### Description Creates a Request for reverse geocoding. Throws RangeError if the coordinate is not finite. ### Method reverse ### Signature reverse(latitude: number, longitude: number) => Request ### Parameters - **latitude** (number) - Required - The latitude coordinate. - **longitude** (number) - Required - The longitude coordinate. ### Returns - **Request** - A plain Request object. ### Throws - **RangeError** - If either coordinate is not finite. ### Example ```ts import { reverse } from "ng-postcode-js/api"; const request = reverse(6.5244, 3.3792); ``` ``` -------------------------------- ### ng_postcode_format(code or prefix) Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Formats a postcode or prefix into its hyphenated form (e.g., 'EK-01-A03-FK-01'). This function is used for display purposes. ```APIDOC ## ng_postcode_format(code or prefix) ### Description Formats a postcode or prefix into its hyphenated form (e.g., 'EK-01-A03-FK-01'). This function is used for display purposes. ### Method Function ### Endpoint ng_postcode_format(code or prefix) ### Parameters - **code or prefix** (ng_postcode or ng_postcode_prefix) - Required - The postcode or prefix to format. ### Request Example ```sql SELECT ng_postcode_format(ng_postcode_parse('EK01A03FK01')); ``` ### Response Returns the hyphenated text representation. ``` -------------------------------- ### AsyncClient.send Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Sends a request using the asynchronous client. It has the same interface as Client for asyncio. ```APIDOC ## AsyncClient.send ### Description Sends a request using the asynchronous client. It has the same interface as Client for asyncio. ### Method send ### Parameters - **request** (Request) - Required - The request to send. ### Returns - **typed response** - The typed response. - **ApiError** - For example 'auth_required' or 'insufficient_credits'. - **TransportError** - A transport error. ### Example ```python from ng_postcode.client import AsyncClient from ng_postcode.api import lookup async with AsyncClient(api_key="nipost_live_...") as client: found = await client.send(lookup(code, level=1)) ``` ``` -------------------------------- ### decode Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Turns a status and body into a typed result. Works with any HTTP client without the client extra. ```APIDOC ## decode ### Description Turns a status and body into a typed result. Works with any HTTP client without the client extra. ### Method decode ### Parameters - **status** (int) - Required - The HTTP status code. - **body** (bytes) - Required - The response body. ### Returns - **typed result** - The typed result. ### Example ```python from ng_postcode.api import decode result = decode(status, body) ``` ``` -------------------------------- ### ng_postcode_prefix_parse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Parses a prefix string and returns the compact prefix (e.g., 'EK01A03') or NULL if not well-formed. ```APIDOC ## ng_postcode_prefix_parse(text) ### Description Parses a prefix string and returns the compact prefix (e.g., 'EK01A03') or NULL if the input is not a valid prefix. ### Function Signature ng_postcode_prefix_parse(text) -> text ### Parameters - **text** (text) - Required - The prefix string to parse. ### Return Value - **text** - The compact prefix, or NULL if invalid. ### Example ```sql SELECT ng_postcode_prefix_parse('EK-01-A03'); -- EK01A03 ``` ``` -------------------------------- ### Api.reverse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Creates a reverse geocoding request for a coordinate. ```APIDOC ## Api.reverse ### Description Creates a reverse geocoding request for a coordinate. ### Method reverse ### Parameters - **latitude** (double) - Required - The latitude of the coordinate. - **longitude** (double) - Required - The longitude of the coordinate. ### Returns - **Request** - A request object that can be sent via a Client or decoded with Api.decode. ### Throws - **IllegalArgumentException** - If the coordinate is not finite. ### Example ```java // Example usage not provided in source. ``` ``` -------------------------------- ### Use ng-postcode in DuckDB Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/README.md Demonstrates parsing a postcode string within a DuckDB query. ```sql SELECT ng_postcode_parse('ek 01 a03 fk 01'); -- EK01A03FK01 ``` -------------------------------- ### ng_postcode_format Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Formats a compact code or prefix into its hyphenated form (e.g., 'EK-01-A03-FK-01'). ```APIDOC ## ng_postcode_format(code or prefix) ### Description Formats a compact postcode or prefix into its hyphenated form. ### Function Signature ng_postcode_format(text) -> text ### Parameters - **code or prefix** (text) - Required - The compact code or prefix to format. ### Return Value - **text** - The hyphenated form of the input. ### Example ```sql SELECT ng_postcode_format('EK01A03FK01'); -- EK-01-A03-FK-01 ``` ``` -------------------------------- ### .ng.parse() Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/polars/README.md Parses a postcode string into its compact form (e.g., 'EK01A03FK01') or returns null if the value is not a well-formed code. ```APIDOC ## .ng.parse() ### Description Parses a postcode string into its compact form (e.g., 'EK01A03FK01') or returns null if the value is not a well-formed code. ### Method Expression ### Endpoint `pl.col("postcode").ng.parse()` ### Returns - **String** - The compact code (e.g., `EK01A03FK01`) or null if invalid. ### Example ```python pl.col("postcode").ng.parse() ``` ``` -------------------------------- ### Parse and validate postcodes in Python Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/README.md Uses the Postcode class and parse function to validate and format a postcode string. ```python from ng_postcode import Postcode, parse match parse("ek 01 a03 fk 01"): case Postcode() as code: print(code, code.compact) # EK-01-A03-FK-01 EK01A03FK01 case error: print(error) # e.g. "invalid lga segment" ``` -------------------------------- ### Codex MCP Add Command Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/mcp/README.md CLI command to add the ng-postcode MCP server to Codex. ```bash codex mcp add ng-postcode --env NG_POSTCODE_API_KEY=nipost_live_... -- uvx ng-postcode-mcp ``` -------------------------------- ### Group by district in Python Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/group-by-place.md Uses the ng-postcode library to parse and truncate postcodes to the district level, then counts occurrences using collections.Counter. ```python from collections import Counter from ng_postcode import Postcode, Segment, parse def district(text: str) -> str | None: """The district a code is in, or None for one that is not well formed.""" code = parse(text) return str(code.truncate(Segment.DISTRICT)) if isinstance(code, Postcode) else None rows = ["EK-01-A03-FK-01", "ek 01 a03 zz 14", "LA11W06TC10", "not a code"] print(Counter(map(district, rows))) # Counter({'EK-01-A03': 2, 'LA-11-W06': 1, None: 1}) ``` -------------------------------- ### Parse and format postcodes offline Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Use Postcode.parse to handle input strings and access various formatting methods like compact() and spaced(). ```java import io.github.adeniyikayodee.ngpostcode.Postcode; import io.github.adeniyikayodee.ngpostcode.Segment; if (Postcode.parse("ek 01 a03 fk 01") instanceof Postcode code) { System.out.println(code); // EK-01-A03-FK-01 System.out.println(code.compact()); // EK01A03FK01, store this System.out.println(code.spaced()); // EK 01 A03 FK 01 System.out.println(code.prefix(Segment.AREA)); // EK-01-A03-FK } ``` -------------------------------- ### Api.nearby Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Creates a nearby search request for postcodes near a coordinate. ```APIDOC ## Api.nearby ### Description Creates a nearby search request for postcodes near a coordinate. ### Method nearby ### Parameters - **latitude** (double) - Required - The latitude of the coordinate. - **longitude** (double) - Required - The longitude of the coordinate. ### Returns - **Request** - A request object that can be sent via a Client or decoded with Api.decode. ### Throws - **IllegalArgumentException** - If the coordinate is not finite. ### Example ```java // Example usage not provided in source. ``` ``` -------------------------------- ### lookup Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Builds a lookup request for a postcode. Level 1 lookups confirm a code is assigned; levels 2 and up return address details and consume credits. ```APIDOC ## lookup ### Description Builds a lookup request for a postcode. Level 1 lookups confirm a code is assigned; levels 2 and up return address details and consume credits. ### Method lookup ### Parameters - **code** (Postcode) - Required - The postcode to look up. - **level** (int) - Optional - The lookup level (1, 2, etc.). ### Returns - **Request** - A request value that can be sent via Client.send or AsyncClient.send. ### Example ```python from ng_postcode.api import lookup request = lookup(code, level=1) ``` ``` -------------------------------- ### Group and select by district Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Use ng_postcode_truncate to aggregate data by district. ```sql SELECT ng_postcode_format(ng_postcode_truncate(postcode, 'district')) AS district, count(*) FROM customers GROUP BY 1; -- EK-01-A03 | 2 ``` -------------------------------- ### Add ng-postcode-api dependency Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Include the ng-postcode-api artifact in your Maven project to enable API requests and decoding. ```xml io.github.adeniyikayodee ng-postcode-api 0.3.2 ``` -------------------------------- ### ng_postcode_parent(prefix) Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/native/pg/README.md Returns the prefix one segment shorter than the given prefix, or NULL if the prefix is a state (i.e., already at the top level). This is used to navigate the hierarchical structure of postcodes. ```APIDOC ## ng_postcode_parent(prefix) ### Description Returns the prefix one segment shorter than the given prefix, or NULL if the prefix is a state (i.e., already at the top level). This is used to navigate the hierarchical structure of postcodes. ### Method Function ### Endpoint ng_postcode_parent(prefix) ### Parameters - **prefix** (ng_postcode_prefix) - Required - The prefix to get the parent of. ### Request Example ```sql SELECT ng_postcode_parent(ng_postcode_prefix_parse('EK01A03')); ``` ### Response Returns the parent prefix as ng_postcode_prefix, or NULL if the input is a state. ``` -------------------------------- ### Validate CSV files via CLI Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/README.md Uses the ng-postcode CLI tool to process a CSV file and output validation results. ```sh pip install ng-postcode ng-postcode --column postcode customers.csv --out checked.csv ``` -------------------------------- ### Prefix.parse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/java/README.md Reads a code cut off after a segment, such as a district prefix, and provides grouping capabilities. ```APIDOC ## Prefix.parse ### Description Reads a code cut off after a segment, such as the district EK-01-A03, and provides grouping capabilities. ### Method parse ### Parameters - **input** (String) - Required - The prefix string to parse. ### Returns - **Prefix** - The parsed prefix. - **ParseError** - An error indicating why parsing failed. ### Example ```java // Example usage not provided in source. ``` ``` -------------------------------- ### Convert a CSV file with ng-postcode Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md Run the ng-postcode command to process a CSV file, specifying the column containing postcodes and the output filename. ```sh ng-postcode orders.csv --column postcode --out checked.csv ``` -------------------------------- ### ng_postcode_parse Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/sql/README.md Parses a postcode string in hyphenated, spaced, or compact form and returns the compact code, or NULL if not well-formed. ```APIDOC ## ng_postcode_parse(text) ### Description Parses a postcode string and returns the compact code (e.g., 'EK01A03FK01') or NULL if the input is not well-formed. ### Function Signature ng_postcode_parse(text) -> text ### Parameters - **text** (text) - Required - The postcode string to parse. Accepts hyphenated, spaced, or compact forms, case-insensitive. ### Return Value - **text** - The compact postcode code, or NULL if invalid. ### Example ```sql SELECT ng_postcode_parse('ek 01 a03 fk 01'); -- EK01A03FK01 ``` ``` -------------------------------- ### Confirm a postcode exists with Python API client Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/docs/index.md Uses the ng_postcode client to send a lookup request to the NIPOST API. Requires an API key and the client feature. Prints an error or the validity and status of the result. Level 1 confirms assignment; higher levels return address details and consume credits. ```python from ng_postcode import Postcode from ng_postcode.api import ApiError, lookup from ng_postcode.client import Client, TransportError # pip install "ng-postcode[client]" with Client(api_key="nipost_live_...") as client: found = client.send(lookup(Postcode("FC03B06AG12"), level=1)) match found: case ApiError() | TransportError(): print(found) # e.g. "invalid_api_key (401): ..." case _: print(found.valid, found.status) # True valid ``` -------------------------------- ### nearby Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/js/packages/ng-postcode-js/README.md Creates a Request for finding nearby postcodes. Throws RangeError if the coordinate is not finite. ```APIDOC ## nearby ### Description Creates a Request for finding nearby postcodes. Throws RangeError if the coordinate is not finite. ### Method nearby ### Signature nearby(latitude: number, longitude: number) => Request ### Parameters - **latitude** (number) - Required - The latitude coordinate. - **longitude** (number) - Required - The longitude coordinate. ### Returns - **Request** - A plain Request object. ### Throws - **RangeError** - If either coordinate is not finite. ### Example ```ts import { nearby } from "ng-postcode-js/api"; const request = nearby(6.5244, 3.3792); ``` ``` -------------------------------- ### autocomplete, reverse geocoding, nearby search Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/python/README.md The ng_postcode.api module covers autocomplete, reverse geocoding, and nearby search. Each function returns a Request value. ```APIDOC ## autocomplete, reverse geocoding, nearby search ### Description The ng_postcode.api module covers autocomplete, reverse geocoding, and nearby search. Each function returns a Request value. ### Functions - **autocomplete** - Builds an autocomplete request. - **reverse_geocoding** - Builds a reverse geocoding request. - **nearby_search** - Builds a nearby search request. ### Returns - **Request** - A request value that can be sent via Client.send or AsyncClient.send. ### Example ```python from ng_postcode.api import autocomplete, reverse_geocoding, nearby_search request = autocomplete(...) request = reverse_geocoding(...) request = nearby_search(...) ``` ``` -------------------------------- ### Parse and validate postcodes in Java Source: https://github.com/adeniyikayodee/ng-postcode/blob/main/README.md Uses the Postcode.parse method to validate a postcode string. ```java import io.github.adeniyikayodee.ngpostcode.Postcode; if (Postcode.parse("ek 01 a03 fk 01") instanceof Postcode code) { System.out.println(code + " " + code.compact()); // EK-01-A03-FK-01 EK01A03FK01 } ```