Skip to main content

Phone Gen

PyPI Downloads PyPI - Python Version PyPI - Implementation

Tests status

International phone number generation

This module was created exclusively for generating test data

Installation

Add the library to your Python project with uv.

uv add phone-gen

Example

from phone_gen import PhoneNumber

phone_number = PhoneNumber("GB")  # ISO 3166-2
# or
phone_number = PhoneNumber("GBR")  # ISO 3166-3
# or
phone_number = PhoneNumber("Great Britain")  # Country name

# Get a phone number
number = phone_number.get_number()
print(number)  # +442908124840

# Get a country code
country_code = phone_number.get_code()
print(country_code)  # 44

# Get a phone number without a country code
number = phone_number.get_number(full=False)
print(number)  # 183782623

# Get a mobile phone number
number = phone_number.get_mobile()
print(number)  # +447911899521

# Get a national phone number
number = phone_number.get_national()
print(number)  # +442408055065
pytest fixture
import pytest
from phone_gen import PhoneNumber


@pytest.fixture
def phone_number():
    def wrap(code):
        return PhoneNumber(code).get_number()

    yield wrap


def test_one(phone_number):
    number = phone_number("DE")
    ...

Using the CLI

usage: phone-gen [-h] [-v] [-n] country [country ...]

International phone number generation

positional arguments:
  country         Country code or country name. Example: "GB" or "GBR" or "Great Britain"

optional arguments:
  -h, --help      show this help message and exit
  -v, --version   show program's version number and exit
  -f, --not-full  Get a phone number without a country code
  -m, --mobile    Get mobile phone number
  -n, --national  Get national phone number

Example

# Get a phone number

$ phone-gen DE
+49791774007056

$ phone-gen DEU
+499968635

$ phone-gen Germany
+49960335800


# Get a phone number without a country code
$ phone-gen -f DE
66999511

$ phone-gen -f Germany
877595

# Get mobile phone number
$ phone-gen -m DE
+491601376066

# Get national phone number
$ phone-gen -n DE
+4940381

Resources

Changelog

Contributing

Contributions are very welcome.

You might want to:

  • Fix spelling errors
  • Improve documentation
  • Add tests for untested code
  • Add new features
  • Fix bugs

Getting started

Install uv, then run the following commands to set up Python 3.12 for development.

git clone https://github.com/tolstislon/phone-gen.git
cd phone-gen
uv python pin 3.12
uv sync --locked
uv run ruff format
uv run ruff check --fix
uv run pytest

Metadata

Release files for phone-gen 3.0.36

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phone-gen 3.0.36
File Size Uploaded Provenance Actions
phone_gen-3.0.36.tar.gz 114.9 kB Without provenance Details for phone_gen-3.0.36.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for phone-gen 3.0.36
File Interpreter ABI Platform Actions
phone_gen-3.0.36-py3-none-any.whl Python 3 none any Details for phone_gen-3.0.36-py3-none-any.whl

Total release size: 147.8 kB

Release files / phone_gen-3.0.36.tar.gz

Download URL phone_gen-3.0.36.tar.gz
Size 114.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e82e7cc760f275346101cb96381bb2275ebfd2ff248d8bde376fc9be66e52490
BLAKE2b-256 checksum
How to use checksums
ca2799a69de1492efcc68a4e25aabf3190f9c4122865c1dee76cd34e2c91b6a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / phone_gen-3.0.36-py3-none-any.whl

Download URL phone_gen-3.0.36-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acc044b193a9cc45c50553614886b1c479e6f38b36ab3a97e3b75a9b9ce94619
BLAKE2b-256 checksum
How to use checksums
ee30420fe5ce3ac5c1f2682627ff2b307675bbfe521fdd6f6694f76cb3f14bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for phone-gen 3.0.36

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0.36 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page