countrycodes-cli 0.1.0rc2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, CountryCodes developers.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: countrycodes-cli
3
+ Version: 0.1.0rc2
4
+ Summary: Command-line interface for the countrycodes library
5
+ License-Expression: BSD-3-Clause
6
+ License-File: LICENSE
7
+ Requires-Dist: countrycodes==0.1.0rc2
8
+ Requires-Dist: rich>=13.7.1
9
+ Requires-Dist: typer>=0.24.1
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+
13
+ <div align="center">
14
+
15
+ # countrycodes-cli
16
+
17
+ [![GitHub](https://img.shields.io/badge/GitHub-code-blue)](https://github.com/oyghen/countrycodes/tree/main/packages/countrycodes-cli)
18
+ [![PyPI](https://img.shields.io/pypi/v/countrycodes-cli?label=PyPI)](https://pypi.org/project/countrycodes-cli/)
19
+ [![License](https://img.shields.io/badge/License-BSD--3--Clause-blue)](https://github.com/oyghen/countrycodes/blob/main/packages/countrycodes-cli/LICENSE)
20
+ [![CI](https://github.com/oyghen/countrycodes/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/oyghen/countrycodes/actions/workflows/ci.yml)
21
+
22
+ </div>
23
+
24
+ Command-line interface for the [`countrycodes`](https://pypi.org/project/countrycodes/)
25
+ ISO 3166-1 lookup library.
26
+
27
+ ## Installation
28
+
29
+ Install as a command-line tool with [uv](https://docs.astral.sh/uv/):
30
+
31
+ ```console
32
+ uv tool install countrycodes-cli
33
+ ```
34
+
35
+ Or install into the active Python environment:
36
+
37
+ ```console
38
+ python -m pip install countrycodes-cli
39
+ ```
40
+
41
+ Requires Python 3.11 or newer. The library dependency is installed automatically.
42
+
43
+ ## Usage
44
+
45
+ Look up a country by code or name:
46
+
47
+ ```console
48
+ countrycodes lookup US
49
+ countrycodes lookup "United Kingdom"
50
+ ```
51
+
52
+ Lookups are displayed as a table by default. Choose JSON output or list all
53
+ countries:
54
+
55
+ ```console
56
+ countrycodes lookup GBR --format json
57
+ countrycodes list
58
+ countrycodes list --format json
59
+ ```
60
+
61
+ The default list is rendered as a table sorted by alpha-2 code, with a row
62
+ number. JSON output remains an unnumbered array of country records.
63
+
64
+ See all options with:
65
+
66
+ ```console
67
+ countrycodes --help
68
+ ```
69
+
70
+ ## License
71
+
72
+ The CLI code is licensed under BSD 3-Clause. The separately distributed
73
+ `countrycodes` library includes ISO registry data under LGPL-2.1-or-later and
74
+ continent assignments from GeoNames under CC BY 4.0; installing the CLI
75
+ installs that library as a dependency.
@@ -0,0 +1,63 @@
1
+ <div align="center">
2
+
3
+ # countrycodes-cli
4
+
5
+ [![GitHub](https://img.shields.io/badge/GitHub-code-blue)](https://github.com/oyghen/countrycodes/tree/main/packages/countrycodes-cli)
6
+ [![PyPI](https://img.shields.io/pypi/v/countrycodes-cli?label=PyPI)](https://pypi.org/project/countrycodes-cli/)
7
+ [![License](https://img.shields.io/badge/License-BSD--3--Clause-blue)](https://github.com/oyghen/countrycodes/blob/main/packages/countrycodes-cli/LICENSE)
8
+ [![CI](https://github.com/oyghen/countrycodes/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/oyghen/countrycodes/actions/workflows/ci.yml)
9
+
10
+ </div>
11
+
12
+ Command-line interface for the [`countrycodes`](https://pypi.org/project/countrycodes/)
13
+ ISO 3166-1 lookup library.
14
+
15
+ ## Installation
16
+
17
+ Install as a command-line tool with [uv](https://docs.astral.sh/uv/):
18
+
19
+ ```console
20
+ uv tool install countrycodes-cli
21
+ ```
22
+
23
+ Or install into the active Python environment:
24
+
25
+ ```console
26
+ python -m pip install countrycodes-cli
27
+ ```
28
+
29
+ Requires Python 3.11 or newer. The library dependency is installed automatically.
30
+
31
+ ## Usage
32
+
33
+ Look up a country by code or name:
34
+
35
+ ```console
36
+ countrycodes lookup US
37
+ countrycodes lookup "United Kingdom"
38
+ ```
39
+
40
+ Lookups are displayed as a table by default. Choose JSON output or list all
41
+ countries:
42
+
43
+ ```console
44
+ countrycodes lookup GBR --format json
45
+ countrycodes list
46
+ countrycodes list --format json
47
+ ```
48
+
49
+ The default list is rendered as a table sorted by alpha-2 code, with a row
50
+ number. JSON output remains an unnumbered array of country records.
51
+
52
+ See all options with:
53
+
54
+ ```console
55
+ countrycodes --help
56
+ ```
57
+
58
+ ## License
59
+
60
+ The CLI code is licensed under BSD 3-Clause. The separately distributed
61
+ `countrycodes` library includes ISO registry data under LGPL-2.1-or-later and
62
+ continent assignments from GeoNames under CC BY 4.0; installing the CLI
63
+ installs that library as a dependency.
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "countrycodes-cli"
3
+ version = "0.1.0rc2"
4
+ description = "Command-line interface for the countrycodes library"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "BSD-3-Clause"
8
+ license-files = ["LICENSE"]
9
+ dependencies = [
10
+ "countrycodes==0.1.0rc2",
11
+ "rich>=13.7.1",
12
+ "typer>=0.24.1",
13
+ ]
14
+
15
+ [project.scripts]
16
+ countrycodes = "countrycodes_cli.cli:app"
17
+
18
+ [tool.uv.sources.countrycodes]
19
+ workspace = true
20
+
21
+ [build-system]
22
+ requires = ["uv_build>=0.11.7,<0.12.0"]
23
+ build-backend = "uv_build"
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "countrycodes-cli"
3
+ version = "0.1.0rc2"
4
+ description = "Command-line interface for the countrycodes library"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "BSD-3-Clause"
8
+ license-files = ["LICENSE"]
9
+ dependencies = ["countrycodes==0.1.0rc2", "rich>=13.7.1", "typer>=0.24.1"]
10
+
11
+ [project.scripts]
12
+ countrycodes = "countrycodes_cli.cli:app"
13
+
14
+ [tool.uv.sources]
15
+ countrycodes = { workspace = true }
16
+
17
+ [build-system]
18
+ requires = ["uv_build>=0.11.7,<0.12.0"]
19
+ build-backend = "uv_build"
@@ -0,0 +1,7 @@
1
+ """Command-line application for the countrycodes library."""
2
+
3
+ __all__ = ["__version__"]
4
+
5
+ from importlib import metadata
6
+
7
+ __version__ = metadata.version(__name__)
@@ -0,0 +1,102 @@
1
+ """Command-line interface for country code lookups."""
2
+
3
+ import json
4
+ from dataclasses import asdict
5
+ from typing import Annotated, Literal
6
+
7
+ import countrycodes as cc
8
+ import typer
9
+ from rich.console import Console
10
+ from rich.table import Table
11
+
12
+ app = typer.Typer(add_completion=False)
13
+
14
+
15
+ @app.callback(invoke_without_command=True)
16
+ def main(
17
+ ctx: typer.Context,
18
+ version: bool = typer.Option(False, "--version", help="Show version and exit."),
19
+ ) -> None:
20
+ pkg_name = cc.__name__
21
+ pkg_version = typer.style(cc.__version__, fg=typer.colors.CYAN)
22
+
23
+ if version:
24
+ typer.echo(f"{pkg_name} {pkg_version}")
25
+ raise typer.Exit()
26
+ if ctx.invoked_subcommand is None:
27
+ typer.echo(f"{pkg_name} {pkg_version} ready. See --help for usage.")
28
+ raise typer.Exit()
29
+
30
+
31
+ @app.command()
32
+ def lookup(
33
+ query: Annotated[str, typer.Argument(help="Country name or ISO code.")],
34
+ output_format: Annotated[
35
+ Literal["text", "json"],
36
+ typer.Option("--format", help="Output format."),
37
+ ] = "text",
38
+ ) -> None:
39
+ """Look up a country by name or ISO code."""
40
+ try:
41
+ country = cc.get_country(query)
42
+ except cc.CountryNotFoundError as error:
43
+ typer.echo(str(error), err=True)
44
+ raise typer.Exit(1) from error
45
+
46
+ if output_format == "json":
47
+ typer.echo(json.dumps(asdict(country), ensure_ascii=False))
48
+ else:
49
+ table = Table(
50
+ "Alpha-2",
51
+ "Alpha-3",
52
+ "Numeric",
53
+ "Continent",
54
+ "Country",
55
+ show_lines=False,
56
+ )
57
+ table.add_row(
58
+ country.alpha2,
59
+ country.alpha3,
60
+ country.numeric,
61
+ country.continent,
62
+ country.name,
63
+ )
64
+ Console().print(table)
65
+
66
+
67
+ @app.command(name="list")
68
+ def list_countries(
69
+ output_format: Annotated[
70
+ Literal["text", "json"],
71
+ typer.Option("--format", help="Output format."),
72
+ ] = "text",
73
+ ) -> None:
74
+ """List all countries and territories."""
75
+ countries = sorted(cc.list_countries(), key=lambda country: country.alpha2)
76
+ if output_format == "json":
77
+ typer.echo(
78
+ json.dumps(
79
+ [asdict(country) for country in countries],
80
+ ensure_ascii=False,
81
+ )
82
+ )
83
+ else:
84
+ table = Table(
85
+ "#",
86
+ "Alpha-2",
87
+ "Alpha-3",
88
+ "Numeric",
89
+ "Continent",
90
+ "Country",
91
+ show_lines=False,
92
+ )
93
+ for index, country in enumerate(countries, start=1):
94
+ table.add_row(
95
+ str(index),
96
+ country.alpha2,
97
+ country.alpha3,
98
+ country.numeric,
99
+ country.continent,
100
+ country.name,
101
+ )
102
+ Console().print(table)