Skip to main content

Python library to retrieve and modify records within ARIN's database through their Reg-RWS service

Project description

pyregrws

GitHub Workflow StatusPyPICodecov

A Python library for interacting with ARIN's Reg-RWS (Registry RESTful Web Service) API. This library provides pydantic-xml models for ARIN payloads and a comprehensive REST client for CRUD operations on ARIN resources like POCs, Customers, Organizations, and Networks.

Features

  • Type-safe models: Built with pydantic-xml for robust XML serialization/deserialization
  • Complete CRUD operations: Create, read, update, and delete ARIN resources
  • Automatic manager integration: Each model type has an associated manager for API operations
  • Error handling: Built-in error response handling with proper HTTP status code mapping
  • Environment configuration: Configurable via environment variables with sensible defaults

Installation

Install from PyPI using pip:

pip install pyregrws

Or using poetry:

poetry add pyregrws

Quick Start

from regrws.api.core import Api
from regrws.models import Poc, Org, Net, Customer

# Initialize the API client
api = Api(
    base_url="https://reg.arin.net/rws",  # Optional, defaults to ARIN production
    api_key="your-api-key-here"           # Or set REGRWS_API_KEY env var
)

# Retrieve a POC by handle
poc = api.poc.from_handle("EXAMPLE-ARIN")
print(f"POC: {poc.first_name} {poc.last_name}")

# Create a new POC
new_poc = api.poc.create(
    contact_type="PERSON",
    first_name="John",
    last_name="Doe",
    company_name="Example Corp",
    iso3166_1={"name": "United States", "code2": "US", "code3": "USA", "e164": "1"},
    street_address=[{"line": "123 Main St"}],
    city="Anytown",
    iso3166_2="VA",
    postal_code="12345",
    phones=[{"type": {"code": "O"}, "number": "555-123-4567"}]
)

# Update and save changes
poc.city = "New City"
updated_poc = poc.save()

# Delete a resource
poc.delete()

Configuration

The library can be configured via environment variables or by passing parameters directly to the Api class:

Environment Variables

  • REGRWS_BASE_URL: Base URL for the ARIN Reg-RWS API (default: https://reg.arin.net/rws)
  • REGRWS_API_KEY: Your ARIN API key (required)

Direct Configuration

from regrws.api.core import Api
from regrws.settings import Settings

# Method 1: Pass parameters directly
api = Api(
    base_url="https://reg.arin.net/rws",
    api_key="your-api-key"
)

# Method 2: Use Settings object
settings = Settings(
    base_url="https://reg.arin.net/rws",
    api_key="your-api-key"
)
api = Api(settings=settings)

API Reference

Core Classes

Api

The main entry point for the library. Automatically creates manager instances for each supported model type.

api = Api(base_url=None, api_key=None, settings=None)

Attributes:

  • poc: Manager for POC operations
  • org: Manager for Organization operations
  • net: Manager for Network operations
  • customer: Manager for Customer operations

BaseManager

All model managers inherit from BaseManager and provide these methods:

  • create(**kwargs): Create a new resource
  • from_handle(handle): Retrieve a resource by handle
  • save(instance): Update an existing resource
  • delete(instance): Delete a resource

Models

All models inherit from BaseModel which provides:

  • save(): Save changes to the resource
  • delete(): Delete the resource
  • absolute_url: Get the full API URL for this resource
  • manager: Access to the associated API manager

Currently Supported Payloads

Core Resources

Ticketing

Error Handling

  • Error - API error responses

Examples

Working with POCs

# Retrieve an existing POC
poc = api.poc.from_handle("EXAMPLE-ARIN")

# Create a new person POC
person_poc = api.poc.create(
    contact_type="PERSON",
    first_name="Jane",
    last_name="Smith",
    company_name="ACME Corp",
    iso3166_1={"name": "United States", "code2": "US", "code3": "USA", "e164": "1"},
    street_address=[{"line": "456 Oak Ave"}, {"line": "Suite 100"}],
    city="Springfield",
    iso3166_2="IL", 
    postal_code="62701",
    phones=[
        {"type": {"code": "O"}, "number": "217-555-0123"},
        {"type": {"code": "F"}, "number": "217-555-0124"}
    ],
    comment=[{"line": "Technical contact for ACME Corp"}]
)

# Create a role POC
role_poc = api.poc.create(
    contact_type="ROLE",
    last_name="Network Operations Center",  # Role name goes in last_name
    company_name="ACME Corp",
    iso3166_1={"name": "United States", "code2": "US", "code3": "USA", "e164": "1"},
    street_address=[{"line": "789 Tech Dr"}],
    city="Austin",
    iso3166_2="TX",
    postal_code="78701",
    phones=[{"type": {"code": "O"}, "number": "512-555-0100"}]
)

Working with Organizations

# Retrieve an organization
org = api.org.from_handle("EXAMPLE-ARIN")

# Update organization details
org.company_name = "Updated Company Name"
updated_org = org.save()

Working with Networks

# Retrieve a network
net = api.net.from_handle("NET-192-0-2-0-1")

# Update network information
net.net_name = "UPDATED-NET-NAME"
updated_net = net.save()

Error Handling

from regrws.models import Error

try:
    poc = api.poc.from_handle("NONEXISTENT-HANDLE")
except Exception as e:
    # The library automatically handles error responses
    print(f"Error occurred: {e}")

Development

Setup

# Clone the repository
git clone https://github.com/jsenecal/pyregrws.git
cd pyregrws

# Install dependencies
poetry install

Running Tests

# Run all tests with coverage
poetry run pytest --cov -n 2 --cov-report xml --cov-report term-missing

# Run a specific test
poetry run pytest tests/test_api.py::TestAPI::test_manager_from_handle

Code Quality

# Lint code
poetry run ruff check

# Format code  
poetry run ruff format

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for your changes
  5. Ensure all tests pass and code is formatted
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Links

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

pyregrws-0.2.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

pyregrws-0.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file pyregrws-0.2.0.tar.gz.

File metadata

  • Download URL: pyregrws-0.2.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-53-generic

File hashes

Hashes for pyregrws-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9ce08bc43081ee2df35e4ae6a6b3603037c222b6aae0b53402749fb9a2882290
MD5 ace09cac3566f072f86aba5c23d5c369
BLAKE2b-256 530faca923a5162ff5dfc44ae9a2b98edc5515cd6dfaccf5619c0ae87e4ae12f

See more details on using hashes here.

File details

Details for the file pyregrws-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyregrws-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-53-generic

File hashes

Hashes for pyregrws-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1238a3e09768f8adf962aee0edb3ad5a2d42979f606bdca7a1c4564db63a4fb
MD5 4f661dd65419a9827d1aba3d4b8919ae
BLAKE2b-256 2845a36f843f29c9f7a6ad57ca94eb282e3717174f188e03b7c7f5d97064a3db

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