Skip to main content

RIPE Database REST API Client for Python

Project description

PyRipe

A modern Python client library for the RIPE Database REST API. PyRipe provides a clean, type-safe interface to interact with RIPE's RESTful web services, built with Pydantic for robust data validation and serialization.

Features

  • Full REST API Coverage: Support for all RIPE Database operations including search, create, update, and delete
  • Type Safety: Built with Pydantic models for compile-time type checking and runtime validation
  • Dual Environment Support: Seamless switching between production (RIPE) and test environments
  • Rich Query Options: Advanced search capabilities with filtering, tagging, and flags
  • Error Handling: Comprehensive exception handling with detailed error messages
  • Modern Python: Requires Python 3.13+ and uses type hints throughout

Installation

pip install pyripe

Or using Poetry:

poetry add pyripe

Quick Start

Initialize the Client

from pyripe import RipeRestApiClient

# Use RIPE production environment
client = RipeRestApiClient(source="RIPE")

# Or use test environment
client = RipeRestApiClient(source="TEST")

# With basic authentication
client = RipeRestApiClient(source="RIPE", basic_auth="your_base64_auth")

Search Objects

# Simple search
result = client.search("192.168.1.1")

# Advanced search with filters
result = client.search(
    query="192.168.1.1",
    sources=["RIPE"],
    type_filters=["inetnum", "route"],
    limit=10,
    offset=0
)

Get Object by Primary Key

from pyripe.models import Attributes, Attribute

# Define the primary key attributes
pk = Attributes(attribute=[
    Attribute(name="inetnum", value="192.168.1.0 - 192.168.1.255")
])

# Get the object
result = client.get_object(pk)

Create a New Object

from pyripe.models import Object, Attributes, Attribute

# Create a new object
new_obj = Object(
    attributes=Attributes(attribute=[
        Attribute(name="inetnum", value="192.168.2.0 - 192.168.2.255"),
        Attribute(name="netname", value="MY-NETWORK"),
        # Add more attributes...
    ])
)

result = client.create_object(new_obj)

Update an Object

# Update existing object
updated_obj = Object(
    attributes=Attributes(attribute=[
        Attribute(name="inetnum", value="192.168.2.0 - 192.168.2.255"),
        Attribute(name="netname", value="MY-UPDATED-NETWORK"),
    ])
)

result = client.update_object(updated_obj)

Delete an Object

# Delete object by primary key
pk = Attributes(attribute=[
    Attribute(name="inetnum", value="192.168.2.0 - 192.168.2.255")
])

result = client.delete_object(pk)

Supported Object Types

PyRipe supports all RIPE Database object types:

Primary Objects

  • aut-num - Autonomous System Number
  • domain - Domain name
  • inet6num - IPv6 address range
  • inetnum - IPv4 address range
  • route - IPv4 route
  • route6 - IPv6 route
  • as-set - AS set
  • filter-set - Filter set
  • inet-rtr - Internet router
  • peering-set - Peering set
  • route-set - Route set
  • rtr-set - Router set

Secondary Objects

  • as-block - AS block
  • irt - Incident Response Team
  • key-cert - Key certificate
  • mntner - Maintainer
  • organisation - Organization
  • person - Person
  • role - Role
  • poem - Poem
  • poetic-form - Poetic form

API Reference

RipeRestApiClient

The main client class for interacting with the RIPE REST API.

Methods

  • get_object(pk, unfiltered=False, managed_attributes=False, abuse_contact=False, resource_holder=False) - Retrieve a specific object
  • search(query, sources=[], inverse_attributes=None, include_tags=None, exclude_tags=None, type_filters=None, flags=None, managed_attributes=False, abuse_contact=False, resource_holder=False, limit=None, offset=None) - Search for objects
  • create_object(obj) - Create a new object
  • update_object(obj) - Update an existing object
  • delete_object(pk) - Delete an object

Data Models

All API responses and requests use Pydantic models for type safety and validation:

  • WhoisResources - Main response container
  • Object - RIPE database object
  • Attributes - Object attributes
  • Attribute - Individual attribute
  • And many more...

Error Handling

PyRipe provides specific exception types for different error scenarios:

from pyripe.exceptions import (
    RipeRestApiError,
    RipeRestApiServerError,
    RipeRestApiInvalidPrimaryKeyError,
    RipeRestApiUnexpectedResponseError
)

try:
    result = client.search("invalid-query")
except RipeRestApiServerError as e:
    print(f"Server error: {e.http_status}")
    print(f"Error messages: {e.ripe_messages}")
except RipeRestApiInvalidPrimaryKeyError:
    print("Invalid primary key provided")
except RipeRestApiError as e:
    print(f"An error occurred: {e}")

API Endpoints

  • Production: https://rest.db.ripe.net
  • Test: https://rest-test.db.ripe.net

For more information about the RIPE REST API, visit the official documentation.

Requirements

  • Python 3.13+
  • requests >= 2.32.5
  • pydantic >= 2.12.5

License

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions:

Acknowledgments

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

pyripe-0.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

pyripe-0.2.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyripe-0.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.1 Darwin/25.3.0

File hashes

Hashes for pyripe-0.2.0.tar.gz
Algorithm Hash digest
SHA256 503c51dfbd25ac22cd7fbe106aa3bac66651ede855766655df485e10caa771c8
MD5 600b3d334175a2283f5f1a8130af2c47
BLAKE2b-256 0e0ecb29d01c6bf9af43211db29ac798ed6dd51bd716b648a119f2de90b36b28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyripe-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.1 Darwin/25.3.0

File hashes

Hashes for pyripe-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0a9b2070ec545a2ecd082e53de2f141775b7ef7920283f4d4769ff79dcd57b3
MD5 75c52617509420414f72c890024c86f1
BLAKE2b-256 603e1edcda4fe5a15ab15de2512e3b14a77f35d092cc9291a79532359bdab347

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