https://github.com/tolstislon/phone-gen
International phone number generation
https://github.com/tolstislon/phone-gen
phone phone-number test-data test-data-generator testing
Last synced: 24 days ago
JSON representation
International phone number generation
- Host: GitHub
- URL: https://github.com/tolstislon/phone-gen
- Owner: tolstislon
- License: mit
- Created: 2020-05-18T00:36:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2026-01-16T11:50:40.000Z (25 days ago)
- Last Synced: 2026-01-17T01:17:01.160Z (25 days ago)
- Topics: phone, phone-number, test-data, test-data-generator, testing
- Language: Python
- Homepage:
- Size: 331 KB
- Stars: 21
- Watchers: 1
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Phone Gen
[](https://pypi.org/project/phone-gen/)
[](https://pepy.tech/project/phone-gen)
[](https://pypi.org/project/phone-gen/)
[](https://github.com/tolstislon/phone-gen)
[](https://github.com/tolstislon/phone-gen/actions/workflows/python-package.yml)
International phone number generation
**This module was created exclusively for generating test data**
Installation
----
Install using pip with
```bash
pip install phone-gen
```
Example
----
```python
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
```python
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
----
```bash
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
```bash
# 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
----
* [Google's libphonenumber](https://github.com/google/libphonenumber)
Changelog
----
* [Releases](https://github.com/tolstislon/phone-gen/releases)
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
```bash
git clone https://github.com/tolstislon/phone-gen.git
cd phone-gen
```
2. Install dev dependencies
```bash
pipenv install --dev
pipenv shell
```
3. Run ruff format
```bash
pipenv run format
```
4. Run ruff check
```bash
pipenv run check
```
5. Run the tests
```bash
pipenv run tests
```