Skip to main content

International phone number generation

Project description

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

Install using pip with

pip install 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

  • python 3.12
  • pipenv 2023.11.15+
  1. Clone the repository
    git clone https://github.com/tolstislon/phone-gen.git
    cd phone-gen
    
  2. Install dev dependencies
    pipenv install --dev
    pipenv shell
    
  3. Run ruff format
    pipenv run format
    
  4. Run ruff check
    pipenv run check
    
  5. Run the tests
    pipenv run tests
    

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phone_gen-3.0.29.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phone_gen-3.0.29-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file phone_gen-3.0.29.tar.gz.

File metadata

  • Download URL: phone_gen-3.0.29.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for phone_gen-3.0.29.tar.gz
Algorithm Hash digest
SHA256 1ef1a0391bc8818ea0a36453499e7c7592612fbda756b0184a9058d8a6e2489c
MD5 a20542e7a738a23505a49ed6134426bd
BLAKE2b-256 2667178a3b04c684d0d26aa4601a4d90b366168fb29b8860c3592bd752afcc28

See more details on using hashes here.

File details

Details for the file phone_gen-3.0.29-py3-none-any.whl.

File metadata

  • Download URL: phone_gen-3.0.29-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for phone_gen-3.0.29-py3-none-any.whl
Algorithm Hash digest
SHA256 78b7a8fdb825c7871f08f59cd3c66eec217689b09fd8b83447a836a112724fe5
MD5 a352429382ce52fadf36669aed19b88b
BLAKE2b-256 336b28523b0810acb93d0d1ba2821cb2a3cda238f48f90865834a979e86e8861

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page