Skip to content

Latest commit

 

History

History
122 lines (72 loc) · 2.12 KB

README.rst

File metadata and controls

122 lines (72 loc) · 2.12 KB

IXF Database - python client

Python RESTful interface to the IXF database,

Installation

The easiest method of installation is go get it directly from PyPI using pip or setuptools by running the respective command below.

pip install -U ixf

or:

easy_install -U ixf

Otherwise you can clone it with:

git clone https://github.com/euro-ix/ixf-client-py.git
cd ixf-client-py

Then install it directly from source:

python setup.py install

or if you want to hack on it, link it directly into your environment with:

python setup.py develop

Using IXFClient

Import the module

from ixf import IXFClient

Create the connection

# anonymous
ixfc = IXFClient()

or

# writes require authentication
ixfc = IXFClient(user='guest', password='guest')

or

# override to localhost for development
ixfc = IXFClient(host="localhost", port=8000, user="test", password="test")

Common operations

# list all records of type IXP
print ixfc.list_all('IXP')

# get IXP42
print ixfc.get('IXP', 42)

# delete IXP42
print ixfc.rm('IXP', 42)

# create new IXP
data = {
    "full_name": "Test IXP",
    "short_name": "TIX",
    }
response = ixfc.save("IXP", data)
ixpid = response['id']

# update from keyword variables
ixfc.update('IXP', 42, full_name="Test IXP", short_name="TIX")

# update from dict
ixfc.update('IXP', 42, **data)

Any errors throw exceptions

# try to get a non existent IXP
ixfc.get('IXP', 999999999)

results in:

KeyError: u'Object not found: IXP.999999999'