Skip to main content

Python async API wrapper for Apaleo Swagger

Project description

Apaleo API Client

CI Coverage pypi downloads versions license

Python async API wrapper for Apaleo Swagger API. Built on top of Pydantic v2 and httpx. Typesafe, fast, and easy to use.

Help

See documentation for more details.

Installation

Install using pip install -U apaleo-api-client or poetry add apaleo-api-client. For more installation options to make Apaleo API Client even faster, see the Installation section in the documentation.

Code Examples

Client Credentials

from apaleoapi import ApaleoAPIClient
from apaleoapi.http.auth import OAuth2ClientCredentialsProvider

# Create a token provider with your API credentials
token_provider = OAuth2ClientCredentialsProvider(
    client_id="your-client-id",
    client_secret="your-client-secret",
    service="My Application"
)

# Create an instance of the client
client = ApaleoAPIClient(token_provider=token_provider)

# Fetch a property by its ID
property_berlin = await client.core.v1.inventory.get_property(property_id="BER")
print(property_berlin)
#> Property id=BER name='Berlin Hotel' address='123 Berlin St.'
print(type(property_berlin))
#> <class 'apaleo_api_client.core.v1.inventory.Property'>

print(property_berlin.id)
#> BER

Authorization Code (FastAPI)

In production, you should use proper session/database storage for the state parameter and token management. This example is simplified for demonstration purposes.

import secrets
import urllib.parse
from dataclasses import asdict
from typing import Any

from fastapi import FastAPI, Query
from fastapi.responses import HTMLResponse

from apaleoapi import ApaleoAPIClient
from apaleoapi.constants import APALEO_API_AUTHORIZE_URL
from apaleoapi.http.auth import OAuth2AuthorizationCodeProvider

app = FastAPI("Apaleo OAuth2 Authorization Code Flow Demo")
CLIENT_ID, CLIENT_SECRET = "your-client-id", "your-client-secret"
REDIRECT_URI = "http://localhost:8000/callback"
auth_states, api_client = {}, None


@app.get("/")
async def index() -> HTMLResponse:
    state = secrets.token_urlsafe(16)
    auth_states[state] = True
    auth_url = f"{APALEO_API_AUTHORIZE_URL}?{
        urllib.parse.urlencode(
            {
                'response_type': 'code',
                'client_id': CLIENT_ID,
                'redirect_uri': REDIRECT_URI,
                'state': state,
                'scope': 'openid profile offline_access identity:account-users.read',
            }
        )
    }"
    return HTMLResponse(f'<a href="{auth_url}">Start OAuth2 Authorization</a>')


@app.get("/callback")
async def callback(code: str = Query(), state: str = Query()) -> dict[str, Any]:
    global api_client
    if state not in auth_states:
        return {"error": "Invalid state"}
    del auth_states[state]

    token_provider = OAuth2AuthorizationCodeProvider(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
        service="Apaleo API Client - Authorization Code Flow",
        redirect_uri=REDIRECT_URI,
        extra={"authorization_code": code},
    )
    await token_provider.refresh_token()
    api_client = ApaleoAPIClient(token_provider=token_provider)
    return {"success": True, "message": "Authenticated! Visit http://localhost:8000/identity"}


@app.get("/identity")
async def get_identity() -> dict[str, Any]:
    user = await api_client.identity.v1.identity.get_current_user()
    return asdict(user)


if __name__ == "__main__":
    print("🚀 Apaleo OAuth2 Authorization Code Flow Demo")
    print(f"📱 Client ID: {CLIENT_ID}")
    print(f"🔗 Redirect URI: {REDIRECT_URI}")
    print()
    print(
        "Run with: poetry run python -m uvicorn path_to_your_module:app --host 0.0.0.0 --port 8000 --reload"
    )
    print("Navigate to: http://localhost:8000")

Contributing

For guidance on setting up a development environment and how to make a contribution to Apaleo API Client, see Contributing to Apaleo API Client.

Reporting a Security Vulnerability

See our security policy.

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

apaleo_api_client-0.1.1.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

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

apaleo_api_client-0.1.1-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file apaleo_api_client-0.1.1.tar.gz.

File metadata

  • Download URL: apaleo_api_client-0.1.1.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apaleo_api_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1abbe1e8877bd345087504332067cbc1b9a3af9a230ce6ca535d6e4f0ee4614e
MD5 861e9d266044b3b6578184e845e4f00d
BLAKE2b-256 17025f03d993611e27ae74a33d5dd77f810336c4e3a46f3941b6c655a7662818

See more details on using hashes here.

Provenance

The following attestation bundles were made for apaleo_api_client-0.1.1.tar.gz:

Publisher: python-publish.yml on lipppy/apaleo-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apaleo_api_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for apaleo_api_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea861cce23de4ef9f59128fb5f023742b1b6816e3c9570bb2f2b4ec1711fb7c4
MD5 77628b52abf4f59e0afe479b3c341ed9
BLAKE2b-256 abd9b96e6cd3c717082483307f8a5751a7e6d80b90b7a7ed1613a22816c9ba95

See more details on using hashes here.

Provenance

The following attestation bundles were made for apaleo_api_client-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on lipppy/apaleo-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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