Skip to main content

Generate fake user and address information for various countries.

Project description

FakeXYZ - Comprehensive Usage Guide

FakeXYZ is a versatile Python library designed to generate realistic-looking fake user and address information for a wide range of countries. It's an invaluable tool for developers and testers who need to populate databases, anonymize sensitive data, or create mock data for application testing and development.

Features

  • Multi-country Support: Generate data tailored to the specifics of numerous countries, including addresses, names, and other localized information.
  • Random Address Generation: Obtain complete address details such as street names, building numbers, cities, states/provinces, postal codes, and timezones.
  • User Information: Generate fake personal profiles including names, genders, phone numbers, and avatar URLs.
  • Intelligent Country Suggestions: The library provides smart suggestions for country names and codes, helping users correct typos and discover supported regions. It prioritizes exact matches, highly confident fuzzy matches, and prefix-based suggestions.

Installation

You can easily install FakeXYZ using pip, the Python package installer. It's recommended to install it in a virtual environment to manage dependencies effectively.

pip install fakexyz

If you encounter performance warnings related to fuzzywuzzy, you can install python-Levenshtein for a faster pure-Python implementation:

pip install python-Levenshtein

Basic Usage: Importing FakeXYZ

To start using the library, you need to import the FakeXYZ class from the fakexyz package:

from fakexyz import FakeXYZ

# Create an instance of the FakeXYZ generator
xyz = FakeXYZ()

Generating Random Addresses

You can generate a single random address or multiple addresses, optionally specifying a country.

Get a Single Random Address

To get a random address, simply call get_random_address(). If no country is specified, a random country will be chosen.

# Get a random address from any supported country
address = xyz.get_random_address()
print(address)

# Example Output:
# {
#     'country': 'United States',
#     'country_code': 'US',
#     'country_flag': '', # No longer directly available in address data
#     'currency': '', # No longer directly available in address data
#     'name': 'Gisselle McLaughlin',
#     'gender': 'female',
#     'phone_number': '(504) 733-0254',
#     'street_address': '5606 Jefferson Hwy',
#     'street_name': '5606 Jefferson Hwy', # Mapped from 'Street'
#     'building_number': '', # No direct equivalent
#     'city': 'New Orleans',
#     'state': 'Louisiana',
#     'postal_code': '70123',
#     'time_zone': '', # No direct equivalent
#     'description': '', # No direct equivalent
#     'avatar_url': '', # No direct equivalent
#     'latitude': '29.945541',
#     'longitude': '-90.184308',
#     '

Get a Random Address for a Specific Country

You can specify a country by its full name or its 2-letter ISO country code (case-insensitive).

# Get a random address for the United States using its code
us_address = xyz.get_random_address(country="US")
print(us_address)

# Get a random address for Bangladesh using its full name
bd_address = xyz.get_random_address(country="Bangladesh")
print(bd_address)

# Get a random address for Germany using its code (case-insensitive)
de_address = xyz.get_random_address(country="de")
print(de_address)

Get Multiple Random Addresses

Use get_random_addresses() to generate a list of addresses. You can specify the count and optionally the country.

# Get 3 random addresses from any supported country
multiple_addresses = xyz.get_random_addresses(count=3)
for addr in multiple_addresses:
    print(addr['country'], addr['city'])

# Get 2 random addresses specifically from Canada
ca_addresses = xyz.get_random_addresses(count=2, country="CA")
for addr in ca_addresses:
    print(addr['name'], addr['street_address'])

Handling Incorrect Country Input and Suggestions

FakeXYZ provides intelligent suggestions if the country input is not recognized.

  • High-Confidence Fuzzy Match: If your input is a common typo for an existing country, it will suggest the most likely correct country.

    try:
        address = xyz.get_random_address(country="bangldesh") # Typo
    except ValueError as e:
        print(e)
    # Expected output: Country 'bangldesh' not found. Did you mean?
    # ๐Ÿ‡ง๐Ÿ‡ฉ Bangladesh (<code>BD</code>)
    
  • Prefix-Based Suggestions: If your input starts with a character or a short sequence that matches multiple countries, it will suggest all relevant countries. This is particularly useful for exploring options.

    try:
        address = xyz.get_random_address(country="g") # Single character
    except ValueError as e:
        print(e)
    # Expected output: Country 'g' not found. Did you mean?
    # ๐Ÿ‡ฉ๐Ÿ‡ช Germany (<code>DE</code>)
    # ๐Ÿ‡ฌ๐Ÿ‡ง United Kingdom (<code>GB</code>)
    # ๐Ÿ‡ฌ๐Ÿ‡ช Georgia (<code>GE</code>)
    # ๐Ÿ‡ฌ๐Ÿ‡ญ Ghana (<code>GH</code>)
    # ๐Ÿ‡ฌ๐Ÿ‡ฑ Greenland (<code>GL</code>)
    # ๐Ÿ‡ฌ๐Ÿ‡ท Greece (<code>GR</code>)
    # ๐Ÿ‡ฌ๐Ÿ‡น Guatemala (<code>GT</code>)
    
    try:
        address = xyz.get_random_address(country="im") # Two characters
    except ValueError as e:
        print(e)
    # Expected output: Country 'im' not found. Did you mean?
    # ๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesia (<code>ID</code>)
    # ๐Ÿ‡ฎ๐Ÿ‡ณ India (<code>IN</code>)
    # ๐Ÿ‡ฎ๐Ÿ‡ถ Iraq (<code>IQ</code>)
    # ๐Ÿ‡ฎ๐Ÿ‡ช Ireland (<code>IE</code>)
    # ๐Ÿ‡ฎ๐Ÿ‡ฑ Israel (<code>IL</code>)
    # ๐Ÿ‡ฎ๐Ÿ‡ธ Iceland (<code>IS</code>)
    # ๐Ÿ‡ฎ๐Ÿ‡น Italy (<code>IT</code>)
    
  • No Close Match: If no reasonable suggestions can be found, a general message will be displayed.

    try:
        address = xyz.get_random_address(country="zz") # No close match
    except ValueError as e:
        print(e)
    # Expected output: Country 'zz' not found.
    # Did you mean?
    # Please check the supported countries list using the `!country` command.
    

Listing Supported Countries

FakeXYZ currently supports 86 countries. Here is a comprehensive list of all supported countries with their flags and 2-letter ISO codes:

  • ๐Ÿ‡ฆ๐Ÿ‡ซ Afghanistan (AF)
  • ๐Ÿ‡ฆ๐Ÿ‡ฑ Albania (AL)
  • ๐Ÿ‡ฉ๐Ÿ‡ฟ Algeria (DZ)
  • ๐Ÿ‡ฆ๐Ÿ‡ฎ Anguilla (AI)
  • ๐Ÿ‡ฆ๐Ÿ‡ถ Antarctica (AQ)
  • ๐Ÿ‡ฆ๐Ÿ‡ท Argentina (AR)
  • ๐Ÿ‡ฆ๐Ÿ‡ฒ Armenia (AM)
  • ๐Ÿ‡ฆ๐Ÿ‡บ Australia (AU)
  • ๐Ÿ‡ฆ๐Ÿ‡น Austria (AT)
  • ๐Ÿ‡ฆ๐Ÿ‡ฟ Azerbaijan (AZ)
  • ๐Ÿ‡ง๐Ÿ‡ฉ Bangladesh (BD)
  • ๐Ÿ‡ง๐Ÿ‡ฒ Bermuda (BM)
  • ๐Ÿ‡ง๐Ÿ‡ด Bolivia (BO)
  • ๐Ÿ‡ง๐Ÿ‡น Bhutan (BT)
  • ๐Ÿ‡ง๐Ÿ‡ท Brazil (BR)
  • ๐Ÿ‡ง๐Ÿ‡ฌ Bulgaria (BG)
  • ๐Ÿ‡ฐ๐Ÿ‡ญ Cambodia (KH)
  • ๐Ÿ‡จ๐Ÿ‡ฒ Cameroon (CM)
  • ๐Ÿ‡จ๐Ÿ‡ฆ Canada (CA)
  • ๐Ÿ‡จ๐Ÿ‡ฑ Chile (CL)
  • ๐Ÿ‡จ๐Ÿ‡ณ China (CN)
  • ๐Ÿ‡จ๐Ÿ‡ด Colombia (CO)
  • ๐Ÿ‡จ๐Ÿ‡ฟ Czechia (CZ)
  • ๐Ÿ‡ฉ๐Ÿ‡ฐ Denmark (DK)
  • ๐Ÿ‡ช๐Ÿ‡ฌ Egypt (EG)
  • ๐Ÿ‡ซ๐Ÿ‡ฎ Finland (FI)
  • ๐Ÿ‡ซ๐Ÿ‡ท France (FR)
  • ๐Ÿ‡ฌ๐Ÿ‡ช Georgia (GE)
  • ๐Ÿ‡ฉ๐Ÿ‡ช Germany (DE)
  • ๐Ÿ‡ฌ๐Ÿ‡ญ Ghana (GH)
  • ๐Ÿ‡ฌ๐Ÿ‡ท Greece (GR)
  • ๐Ÿ‡ฌ๐Ÿ‡ฑ Greenland (GL)
  • ๐Ÿ‡ฌ๐Ÿ‡น Guatemala (GT)
  • ๐Ÿ‡ญ๐Ÿ‡ฐ Hong Kong (HK)
  • ๐Ÿ‡ฎ๐Ÿ‡ธ Iceland (IS)
  • ๐Ÿ‡ฎ๐Ÿ‡ณ India (IN)
  • ๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesia (ID)
  • ๐Ÿ‡ฎ๐Ÿ‡ถ Iraq (IQ)
  • ๐Ÿ‡ฎ๐Ÿ‡ช Ireland (IE)
  • ๐Ÿ‡ฎ๐Ÿ‡ฑ Israel (IL)
  • ๐Ÿ‡ฎ๐Ÿ‡น Italy (IT)
  • ๐Ÿ‡ฏ๐Ÿ‡ต Japan (JP)
  • ๐Ÿ‡ฏ๐Ÿ‡ด Jordan (JO)
  • ๐Ÿ‡ฐ๐Ÿ‡ฟ Kazakhstan (KZ)
  • ๐Ÿ‡ฐ๐Ÿ‡ช Kenya (KE)
  • ๐Ÿ‡ง๐Ÿ‡ญ Kingdom of Bahrain (BH)
  • ๐Ÿ‡ง๐Ÿ‡ช Kingdom of Belgium (BE)
  • ๐Ÿ‡ฑ๐Ÿ‡ง Lebanon (LB)
  • ๐Ÿ‡ฒ๐Ÿ‡พ Malaysia (MY)
  • ๐Ÿ‡ฒ๐Ÿ‡ป Maldives (MV)
  • ๐Ÿ‡ฒ๐Ÿ‡ท Mauritania (MR)
  • ๐Ÿ‡ฒ๐Ÿ‡ฝ Mexico (MX)
  • ๐Ÿ‡ฒ๐Ÿ‡ฆ Morocco (MA)
  • ๐Ÿ‡ฒ๐Ÿ‡ฒ Myanmar (MM)
  • ๐Ÿ‡ณ๐Ÿ‡ต Nepal (NP)
  • ๐Ÿ‡ณ๐Ÿ‡ฑ Netherlands (NL)
  • ๐Ÿ‡ณ๐Ÿ‡ฟ New Zealand (NZ)
  • ๐Ÿ‡ณ๐Ÿ‡ช Niger (NE)
  • ๐Ÿ‡ณ๐Ÿ‡ฌ Nigeria (NG)
  • ๐Ÿ‡ณ๐Ÿ‡ด Norway (NO)
  • ๐Ÿ‡ด๐Ÿ‡ฒ Oman (OM)
  • ๐Ÿ‡ต๐Ÿ‡ฐ Pakistan (PK)
  • ๐Ÿ‡ต๐Ÿ‡ธ Palestine (PS)
  • ๐Ÿ‡ต๐Ÿ‡ฆ Panama (PA)
  • ๐Ÿ‡ต๐Ÿ‡ช Peru (PE)
  • ๐Ÿ‡ต๐Ÿ‡ญ Philippines (PH)
  • ๐Ÿ‡ต๐Ÿ‡ฑ Poland (PL)
  • ๐Ÿ‡ต๐Ÿ‡น Portugal (PT)
  • ๐Ÿ‡ถ๐Ÿ‡ฆ Qatar (QA)
  • ๐Ÿ‡ท๐Ÿ‡ด Romania (RO)
  • ๐Ÿ‡ท๐Ÿ‡บ Russia (RU)
  • ๐Ÿ‡ธ๐Ÿ‡ฒ San Marino (SM)
  • ๐Ÿ‡ธ๐Ÿ‡ฆ Saudi Arabia (SA)
  • ๐Ÿ‡ธ๐Ÿ‡ฌ Singapore (SG)
  • ๐Ÿ‡ฟ๐Ÿ‡ฆ South Africa (ZA)
  • ๐Ÿ‡ฐ๐Ÿ‡ท South Korea (KR)
  • ๐Ÿ‡ช๐Ÿ‡ธ Spain (ES)
  • ๐Ÿ‡ฑ๐Ÿ‡ฐ Sri Lanka (LK)
  • ๐Ÿ‡ธ๐Ÿ‡ฉ Sudan (SD)
  • ๐Ÿ‡ธ๐Ÿ‡ช Sweden (SE)
  • ๐Ÿ‡จ๐Ÿ‡ญ Switzerland (CH)
  • ๐Ÿ‡น๐Ÿ‡ผ Taiwan (TW)
  • ๐Ÿ‡น๐Ÿ‡ฟ Tanzania (TZ)
  • ๐Ÿ‡น๐Ÿ‡ญ Thailand (TH)
  • ๐Ÿ‡น๐Ÿ‡ท Turkiye (TR)
  • ๐Ÿ‡บ๐Ÿ‡ฌ Uganda (UG)
  • ๐Ÿ‡บ๐Ÿ‡ฆ Ukraine (UA)
  • ๐Ÿ‡ฆ๐Ÿ‡ช United Arab Emirates (AE)
  • ๐Ÿ‡ฌ๐Ÿ‡ง United Kingdom (GB)
  • ๐Ÿ‡บ๐Ÿ‡ธ United States (US)
  • ๐Ÿ‡ป๐Ÿ‡ช Venezuela (VE)
  • ๐Ÿ‡ป๐Ÿ‡ณ Vietnam (VN)
  • ๐Ÿ‡พ๐Ÿ‡ช Yemen (YE)

You can also programmatically retrieve a list of all countries currently supported by the library:

from fakexyz import FakeXYZ

xyz = FakeXYZ()
countries = xyz.get_available_countries()
print("Supported Countries:", countries)

# Example Output:
# Supported Countries: ['Afghanistan', 'Albania', 'Algeria', ..., 'Yemen', 'Zambia']

Available Data Fields

The get_random_address method returns a dictionary containing the following fields:

  • country: Full name of the country (e.g., "United States")
  • country_code: 2-letter ISO country code (e.g., "US")
  • country_flag: Emoji flag of the country (e.g., "๐Ÿ‡บ๐Ÿ‡ธ") - Note: This field will be empty as flags are no longer in the raw data.
  • currency: Currency code (e.g., "USD") - Note: This field will be empty as currency is no longer in the raw data.
  • name: Full name of the person (e.g., "John Doe") - Mapped from 'Full Name' in raw data.
  • gender: Gender of the person (e.g., "Male", "Female")
  • phone_number: Phone number (e.g., "+1-555-123-4567") - Mapped from 'Phone Number' in raw data.
  • street_address: Full street address (e.g., "123 Main St") - Mapped from 'Street' in raw data.
  • street_name: Name of the street (e.g., "Main St") - Currently mapped from 'Street' in raw data as no separate field exists.
  • building_number: Building or house number - No direct equivalent in raw data, will be empty.
  • city: City (e.g., "Anytown") - Mapped from 'City/Town' in raw data.
  • state: State or province (e.g., "CA") - Mapped from 'State/Province/Region' in raw data.
  • postal_code: Postal or ZIP code (e.g., "90210") - Mapped from 'Zip/Postal Code' in raw data.
  • time_zone: Timezone offset (e.g., "-08:00") - No direct equivalent in raw data, will be empty.
  • description: Timezone description (e.g., "Pacific Standard Time") - No direct equivalent in raw data, will be empty.
  • avatar_url: URL to a random avatar image - No direct equivalent in raw data, will be empty.
  • latitude: Latitude coordinate (e.g., "34.0522")
  • longitude: Longitude coordinate (e.g., "-118.2437")
  • birthday: Date of birth (e.g., "1990-01-01")
  • social_security_number: Social Security Number (e.g., "XXX-XX-XXXX")
  • credit_card_brand: Brand of the credit card (e.g., "Visa")
  • credit_card_number: Credit card number (e.g., "XXXXXXXXXXXXXXXX")
  • expire: Credit card expiration date (e.g., "2025/12")
  • cvv: Credit card CVV (e.g., "123")

IBAN Generation and Validation

FakeXYZ now includes functionality to generate and validate International Bank Account Numbers (IBANs) using the schwifty library. This feature supports 42 countries, allowing for robust IBAN operations for a significant number of regions.

The countries currently supported for IBAN generation and validation are: Andorra, Austria, Belgium, Bosnia and Herzegovina, Bulgaria, Costa Rica, Croatia, Czech Republic, Cyprus, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Iceland, Italy, Israel, Kazakhstan, Latvia, Lithuania, Luxembourg, Moldova, Monaco, Netherlands, Norway, Poland, Portugal, Romania, Saudi Arabia, Serbia, Slovakia, Slovenia, South Africa, Spain, Sweden, Switzerland, Turkiye, Ukraine, United Arab Emirates, United Kingdom.

Generate a Random IBAN

You can generate a random, valid IBAN, optionally specifying a country code or bank code.

from fakexyz.iban import generate_random_iban

# Generate a random IBAN from any supported country
random_iban = generate_random_iban()
print(f"Random IBAN: {random_iban.formatted}")

# Generate a German IBAN
german_iban = generate_random_iban(country_code="DE")
print(f"German IBAN: {german_iban.formatted}")

# Generate a German IBAN from a specific bank (if supported by schwifty's registry)
# Note: Not all bank codes are available for random generation.
# lloyds_iban = generate_random_iban(country_code="GB", bank_code="LOYD")
# print(f"Lloyds Bank IBAN: {lloyds_iban.formatted}")

Validate an IBAN

You can validate an IBAN string to check its correctness.

from fakexyz.iban import validate_iban

# Validate a correct IBAN
valid_iban_string = "DE89370400440532013000"
is_valid = validate_iban(valid_iban_string)
print(f"Is '{valid_iban_string}' valid? {is_valid}")

# Validate an incorrect IBAN
invalid_iban_string = "DE89370400440532013001" # Incorrect checksum
is_invalid = validate_iban(invalid_iban_string)
print(f"Is '{invalid_iban_string}' valid? {is_invalid}")

Get Detailed IBAN Information

Retrieve comprehensive details about an IBAN, including its validation status, any messages, and associated bank data.

from fakexyz.iban import get_iban_info
import json

# Get info for a valid German IBAN
iban_info = get_iban_info("DE89370400440532013000")
print(json.dumps(iban_info, indent=2, ensure_ascii=False))

# Get info for an invalid IBAN
invalid_iban_info = get_iban_info("DE89370400440532013001")
print(json.dumps(invalid_iban_info, indent=2, ensure_ascii=False))

# Get info for an IBAN where bank data might not be in schwifty's registry
generic_gb_iban = "GB33BUKB20201555555555"
generic_gb_info = get_iban_info(generic_gb_iban)
print(json.dumps(generic_gb_info, indent=2, ensure_ascii=False))

Contributing

Contributions to FakeXYZ are highly encouraged! If you have suggestions for new features, bug reports, or want to add data for more countries, please feel free to:

  1. Submit an Issue: For bug reports or feature requests, open an issue on the GitHub repository.
  2. Submit a Pull Request: If you've implemented a new feature or fixed a bug, submit a pull request. Ensure your code adheres to the project's style and includes relevant tests.

License

This project is open-source and licensed under the MIT License. See the LICENSE.txt file in the repository for full details.

Project details


Download files

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

Source Distribution

fakexyz-2.4.tar.gz (139.6 kB view details)

Uploaded Source

Built Distribution

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

fakexyz-2.4-py3-none-any.whl (189.8 kB view details)

Uploaded Python 3

File details

Details for the file fakexyz-2.4.tar.gz.

File metadata

  • Download URL: fakexyz-2.4.tar.gz
  • Upload date:
  • Size: 139.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for fakexyz-2.4.tar.gz
Algorithm Hash digest
SHA256 6d4f69f089b77009bbe56527282d9837fb2ebbe3abb35d2cb50f00704a7d645a
MD5 339e24e1bd470d374ea2d81e1fa682a8
BLAKE2b-256 81a598162905a99cbe7add593f08f5d33b159c91149f38bbf040fce94e744973

See more details on using hashes here.

File details

Details for the file fakexyz-2.4-py3-none-any.whl.

File metadata

  • Download URL: fakexyz-2.4-py3-none-any.whl
  • Upload date:
  • Size: 189.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for fakexyz-2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 31d0cf2fc149f37fc0de9157fba9cf2b31d731f59a0e8335c125689f5d9661fa
MD5 0853e6ee6b662107ede27e0c47be21a4
BLAKE2b-256 5b0b3185fcb7925e415b6b78f384d619b22a85715309cabf705234160155c7f3

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