python-namesilo

python-namesilo is a lightweight Python wrapper around the NameSilo API. It provides a thin, pragmatic interface for common account and domain management tasks such as:

  • Domain availability checks and registration

  • Domain renewal and information lookup

  • Nameserver updates

  • WHOIS privacy management

  • Domain lock/unlock

  • Contact profile management

  • Account balance and funding

  • DNS record listing/creation/update

The primary entry point is namesilo.core.NameSilo.

Installation

Install from PyPI:

pip install python-namesilo

Authentication and environment

You need an API key from your NameSilo account.

  • Production API base URL is used when sandbox=False.

  • Sandbox API base URL is used when sandbox=True (default).

Quickstart

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)

domain = "example.com"
if client.check_domain(domain):
    client.register_domain(domain, years=1, private=1, auto_renew=0)

Common usage

List domains

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)
domains = client.list_domains()
print(domains)

Get domain information

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)
info = client.get_domain_info("example.com")

print(info.status)
print(info.expires)
print(info.name_servers)

Update nameservers

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)
client.change_domain_nameservers(
    "example.com",
    primary_ns="ns1.example.net",
    secondary_ns="ns2.example.net",
)

WHOIS privacy

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)
client.add_domain_privacy("example.com")
client.remove_domain_privacy("example.com")

Domain lock/unlock

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)
client.lock_domain("example.com")
client.unlock_domain("example.com")

Contacts

from namesilo.core import ContactModel, NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)

contacts = client.list_contacts()
for c in contacts:
    print(c)

new_contact = ContactModel(
    first_name="Jane",
    last_name="Doe",
    address="1 Main Street",
    city="Belgrade",
    state="RS",
    country="RS",
    zip="11000",
    email="jane@example.com",
    phone="+381.111111",
)

client.add_contact(new_contact)

DNS records

from namesilo.core import NameSilo

client = NameSilo(token="YOUR_API_KEY", sandbox=False)

records = client.list_dns_records("example.com")
print(records)

record_id = client.add_dns_record(
    "example.com",
    record_type="A",
    record_host="@",
    record_value="203.0.113.10",
    ttl=3600,
)

client.update_dns_record(
    "example.com",
    record_id=str(record_id),
    record_host="@",
    record_value="203.0.113.11",
    ttl=3600,
)

Error handling

API errors are mapped to custom exceptions defined in namesilo.exceptions.

from namesilo.core import NameSilo
from namesilo.exceptions import (
    APIRequestError,
    DomainAlreadyLocked,
    InsufficientFunds,
    InvalidAPIKey,
    InvalidDomainSyntax,
    IPForbidden,
)

client = NameSilo(token="YOUR_API_KEY", sandbox=False)

try:
    balance = client.get_account_balance()
except InvalidAPIKey as exc:
    print(f"Invalid API key: {exc}")
except IPForbidden as exc:
    print(f"Your IP is not allowed to access the API: {exc}")
except APIRequestError as exc:
    print(f"Request error: {exc}")

try:
    client.lock_domain("example.com")
except DomainAlreadyLocked as exc:
    print(f"Domain already locked: {exc}")
except InvalidDomainSyntax as exc:
    print(f"Invalid domain syntax: {exc}")

Available exception types

The following exception classes are defined in namesilo.exceptions:

  • namesilo.exceptions.HTTPSNotUsed

  • namesilo.exceptions.NoAPIVersionSpecified

  • namesilo.exceptions.InvalidAPIVersion

  • namesilo.exceptions.NoTypeSpecified

  • namesilo.exceptions.InvalidAPIType

  • namesilo.exceptions.NoOperationSpecified

  • namesilo.exceptions.InvalidAPIOperation

  • namesilo.exceptions.MissingParameters

  • namesilo.exceptions.NoApiKeySpecified

  • namesilo.exceptions.InvalidAPIKey

  • namesilo.exceptions.InvalidUser

  • namesilo.exceptions.APINotAvailableSubs

  • namesilo.exceptions.IPForbidden

  • namesilo.exceptions.InvalidDomainSyntax

  • namesilo.exceptions.CreditCardProfileDoesntExists

  • namesilo.exceptions.CreditCardNotVerified

  • namesilo.exceptions.InsufficientFunds

  • namesilo.exceptions.APIKeyPass

  • namesilo.exceptions.DomainNotActive

  • namesilo.exceptions.InternalSystemError

  • namesilo.exceptions.GeneralError

  • namesilo.exceptions.DomainAlreadyAutoRenew

  • namesilo.exceptions.DomainAlreadyNotAutoRenew

  • namesilo.exceptions.DomainAlreadyLocked

  • namesilo.exceptions.DomainAlreadyUnlocked

  • namesilo.exceptions.NameServerUpdateError

  • namesilo.exceptions.DomainAlreadyPrivate

  • namesilo.exceptions.DomainAlreadyNotPrivate

  • namesilo.exceptions.DomainProcessingError

  • namesilo.exceptions.DomainAlreadyActiveInSystem

  • namesilo.exceptions.InvalidNumberOfYears

  • namesilo.exceptions.CentralRegistryNotResponding

  • namesilo.exceptions.InvalidSandboxAccount

  • namesilo.exceptions.DomainNotRenewed

  • namesilo.exceptions.DomainNotTransferred

  • namesilo.exceptions.NoDomainTransfer

  • namesilo.exceptions.InvalidDomainNameOrExtension

  • namesilo.exceptions.DNSModificationError

  • namesilo.exceptions.APIRequestError

API reference

class namesilo.core.NameSilo(token, sandbox: bool = True)

Creating Namesilo object with given token

Parameters:
  • token – access token from namesilo.com

  • sandbox – true or false

add_account_funds(amount: float, payment_id: int) Tuple[bool, float]

Adding funds to Namesilo account

Parameters:
  • amount (float) – amount to add

  • payment_id (int) – ID of payment (credit card)

Returns:

Status and amount after adding funds, example: (True, 150.00)

Return type:

tuple

add_contact(contact: ContactModel) bool

Adding new contact for current account

Parameters:

contact (ContactModel)

Returns:

Status for adding contact

Return type:

bool

add_dns_record(domain_name: str, record_type: str, record_host: str, record_value: str, ttl: int = 7207) int

Add DNS record to specified domain name

Parameters:
  • domain_name (str) – Domain name for adding DNS record

  • record_type (str) – The type of resources record to add

  • record_host (str) – The hostname for the new record

  • record_value (str) – The value for the resource record

  • ttl (int) – The TTL for the new record

Returns:

Returns record id for specified domain record

Return type:

int

add_domain_privacy(domain_name: str) bool

Adds privacy to specified domain name

Parameters:

domain_name (str) – Domain name for adding privacy

Returns:

Status of action

Return type:

bool

auto_renew_domain(domain_name: str) bool

Set auto-renew to specific domain

Parameters:

domain_name (str) – Domain name

Returns:

Status of action

Return type:

bool

change_domain_nameservers(domain: str, primary_ns: str, secondary_ns: str) bool

Change name server for specified domain

Parameters:
  • domain (str) – Domain name

  • primary_ns (str) – Primary name Server

  • secondary_ns (str) – Secondary name server

Returns:

Status of action

Return type:

bool

check_domain(domain_name: str) bool

Check if domain name is available

Parameters:

domain_name (str) – Domain name for checking

Returns:

Availability of domain

Return type:

bool

delete_contact(contact_id) bool

Delete contact from NameSilo account

Parameters:

contact_id (int) – Contact ID

Returns:

Return type:

None

get_account_balance() float

Returns current account balance

Returns:

current account balance

Return type:

float

get_domain_info(domain_name: str) DomainInfo

Returns information about specified domain

Parameters:

domain_name (str) – name of domain

Returns:

domain information

Return type:

DomainInfo

get_prices()

Returns all prices for supported TLDs

Returns:

Prices for supported TLDs

Return type:

dict

list_contacts() List[ContactModel]

Returns list of all contacts for current account

Returns:

list of all contacts

Return type:

list

list_dns_records(domain_name) List

List all DNS records for specified domain name

Parameters:

domain_name (str) – Domain name for listing DNS records

Returns:

Returns a list of DNS records for specified domain name

Return type:

list

list_domains() List

List all domains registered with current account

Returns:

list of registered domains

Return type:

list

lock_domain(domain_name: str) bool
Parameters:

domain_name (str)

Returns:

register_domain(domain_name: str, years: int = 1, auto_renew: int = 0, private: int = 0) bool

Register a new domain name

Parameters:
  • domain_name (str) – name of domain

  • years (int) – how long to register domain

  • auto_renew (int) – turn on or off auto-renewal option

  • private (int) – hide your private information (WHOIS)

Returns:

status of domain registration

Return type:

bool

remove_auto_renew_domain(domain_name: str) bool

Remove auto-renew to specific domain

Parameters:

domain_name (str) – Domain name

Returns:

Status of action

Return type:

bool

remove_domain_privacy(domain_name: str) bool

Removes privacy for specified domain name

Parameters:

domain_name (str) – Domain name for removing privacy

Returns:

Status of action

Return type:

bool

renew_domain(domain_name: str, years: int = 1) bool

Renew domain name

Parameters:
  • domain_name (str) – domain name for renewal

  • years (int)

Returns:

status of renewal

Return type:

bool

unlock_domain(domain_name: str) bool
Parameters:

domain_name (str)

Returns:

update_contact(contact: ContactModel) bool

Update existing contact with new information

Parameters:

contact (ContactModel) – new contact information

Returns:

status of action

Return type:

bool

update_dns_record(domain_name: str, record_id: str, record_host: str, record_value: str, ttl: int = 7207) int

Update an existing DNS resource record

Parameters:
  • domain_name (str) – Domain name for updating DNS record

  • record_id (str) – The unique ID of the resource record

  • record_host (str) – The hostname to use

  • record_value (str) – The value for the resource record

  • ttl (int) – The TTL for this record

Returns:

Returns record id for updated domain record

Return type:

int

class namesilo.core.ContactModel(**kwargs)

Model for manipulating NameSilo contacts

Parameters:
  • contact_id (str) – Contact ID

  • first_name (str) – First Name

  • last_name (str) – Last Name

  • address (str) – Address

  • city (str) – City

  • state (str) – State

  • country (str) – Country

  • email (str) – Email address

  • phone (str) – Telephone number

  • zip (str) – ZIP Code

static convert_contact_model(reply)

Convert standard Namesilo reply to ContactModel

Parameters:

reply – Namesilo Contact response

Returns:

Populated ContactModel from Namesilo

Return type:

ContactModel

class namesilo.common.DomainInfo(auto_renew: bool, created: datetime.datetime, expires: datetime.datetime, locked: bool, private: bool, status: str, traffic_type: str, name_servers: List[str], contacts: 'Contact')

Indices and tables