Skip to main content

GLPI Python SDK

Modern Python SDK for GLPI REST API with sync/async support.

Note: This library was inspired by py-glpi and rewritten with modern Python practices, httpx support, and async capabilities.

Features

  • Sync & Async - Full support for synchronous and asynchronous operations
  • httpx - Modern HTTP client with HTTP/2 support
  • FastAPI Ready - Compatible with FastAPI and other async frameworks
  • Configurable Timeout - Full control over connection timeouts
  • Auto Retry - Automatic token renewal on 401/403
  • Organized Exceptions - Exceptions by category (auth, network, resource)
  • Type Hints - Fully typed for better DX

Installation

pip install glpi-python-sdk

With HTTP/2 support:

pip install glpi-python-sdk[http2]

For use with FastAPI:

pip install glpi-python-sdk[fastapi]

Quick Start

Synchronous Mode

from glpi_python_sdk import GLPISession

# Basic authentication
with GLPISession(
    api_url="https://glpi.example.com/apirest.php",
    app_token="your_app_token",
    auth_type="basic",
    user="admin",
    password="password",
    timeout=30.0
) as glpi:
    # Get all tickets
    tickets = glpi.get_all_items("Ticket")
    print(tickets.json())

    # Get specific item
    ticket = glpi.get_item("Ticket", 123)
    print(ticket.json())

Asynchronous Mode (FastAPI)

from glpi_python_sdk import AsyncGLPISession

async with AsyncGLPISession(
    api_url="https://glpi.example.com/apirest.php",
    app_token="your_app_token",
    auth_type="user_token",
    user_token="your_user_token"
) as glpi:
    tickets = await glpi.get_all_items("Ticket")
    print(tickets.json())

FastAPI Example

from fastapi import FastAPI, Depends
from glpi_python_sdk import AsyncGLPISession
from contextlib import asynccontextmanager

app = FastAPI()

@asynccontextmanager
async def get_glpi():
    async with AsyncGLPISession(
        api_url="https://glpi.example.com/apirest.php",
        app_token="token",
        auth_type="user_token",
        user_token="user_token"
    ) as session:
        yield session

@app.get("/tickets")
async def list_tickets():
    async with get_glpi() as glpi:
        response = await glpi.get_all_items("Ticket")
        return response.json()

Configuration

from glpi_python_sdk import GLPISession, ClientConfig

session = GLPISession(
    api_url="https://glpi.example.com/apirest.php",
    app_token="app_token",
    auth_type="basic",
    user="admin",
    password="password",
    # Connection settings
    timeout=30.0,           # Request timeout (seconds)
    connect_timeout=10.0,   # Connection timeout (seconds)
    verify_ssl=True,        # Verify SSL certificates
    max_retries=3,          # Retries on failure
    auto_refresh_token=True # Automatically refresh token
)

Exceptions

from glpi_python_sdk import (
    GLPIError,              # Base
    AuthenticationError,    # Authentication errors
    InvalidCredentialsError,
    SessionTokenError,
    UnauthorizedError,
    ForbiddenError,
    NetworkError,           # Network errors
    ConnectionError,
    TimeoutError,
    ResourceError,          # Resource errors
    ResourceNotFoundError,
    ItemCreationError,
)

try:
    ticket = glpi.get_item("Ticket", 99999)
except ResourceNotFoundError as e:
    print(f"Ticket not found: {e}")
except NetworkError as e:
    print(f"Connection error: {e}")

Credits

This library was inspired by py-glpi by Teclib.

License

MIT

Download files

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

Source Distribution

glpi_python_sdk-2.1.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

glpi_python_sdk-2.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file glpi_python_sdk-2.1.0.tar.gz.

File metadata

  • Download URL: glpi_python_sdk-2.1.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for glpi_python_sdk-2.1.0.tar.gz
Algorithm Hash digest
SHA256 955cfb6ca3a306633f89894806a5b05edac8c8fa68f1309905b9ef37b85970c4
MD5 7dfb6053a5749cfaf3e2e0261796d915
BLAKE2b-256 1fa0da19a78720129e9a643029319bc5a14ab01ea94af987d33e9bda46a0470a

See more details on using hashes here.

File details

Details for the file glpi_python_sdk-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for glpi_python_sdk-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0183febfbdf6ef47d93aefec6814c9c8792fc6e7f422acfeeccd4954ca2b67e4
MD5 371ed2fd306b5538f0d3fd49ce17ea9f
BLAKE2b-256 5fc13046261333786ee04f17dbe09e1aa585ac16255b4377baa1abe541fd33f8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 files

2.0.1

2 files

2.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page