Skip to main content

Python library for connecting to dry-api

Project description

dry-apy-connector

Python client for Navigo3 API.

Features

  • 🔐 Authentication - credentials or token-based login
  • 🔄 Automatic logout - automatic logout when context exits or program ends
  • 🧵 Thread-safe - safe for concurrent API calls
  • Batch execution - execute multiple requests in a single call

Installation

pip install dry_apy_connector

Using uv

# From PyPI
uv add dry-apy-connector

Quick Start

from dry_apy_connector.ApiConnector import ApiConnector

# Using context manager (recommended) - logout is automatic
with ApiConnector("https://instance.navigo3.com/API") as connector:
    # Login with credentials
    connector.login_with_credentials("username", "password")

    # Execute API call
    project = connector.execute("project/get", {"id": 88})
    print(project)
    # Logout happens automatically when exiting the context

Token Authentication

with ApiConnector("https://instance.navigo3.com/API") as connector:
    connector.login_with_token("your-api-token")
    result = connector.execute("project/get", {"id": 88})
    # Logout happens automatically

Usage

Batch Execution (Same Endpoint)

Execute multiple calls to the same endpoint efficiently:

from dry_apy_connector.ApiConnector import ApiConnector

with ApiConnector("https://instance.navigo3.com/API") as connector:
    connector.login_with_credentials("user", "password")

    # Multiple inputs for the same endpoint
    inputs = [{"id": 1}, {"id": 2}, {"id": 3}]
    projects = connector.execute_endpoint_batch("project/get", inputs)

    for project in projects:
        print(project)

Batch Execution (Mixed Endpoints)

Execute multiple different API calls in a single HTTP request:

from dry_apy_connector.ApiConnector import ApiConnector
from uuid import uuid1

with ApiConnector("https://instance.navigo3.com/API") as connector:
    connector.login_with_credentials("user", "password")

    # Create batch with different endpoints
    batch = [
        ApiConnector.create_request(
            str(uuid1()), "project/get", "EXECUTE", {"id": 1}
        ),
        ApiConnector.create_request(
            str(uuid1()), "user/list", "EXECUTE", {}
        ),
    ]

    responses = connector.call(batch)

Validation

Validate input data before execution:

with ApiConnector("https://instance.navigo3.com/API") as connector:
    connector.login_with_credentials("user", "password")

    validation = connector.validate("project/create", {"name": "Test"})
    if validation.get("valid"):
        result = connector.execute("project/create", {"name": "Test"})

Custom Logger

from loguru import logger

connector = ApiConnector("https://instance.navigo3.com/API", logger=logger)

API Reference

ApiConnector

ApiConnector(base_address: str, logger: Optional[LoggerInterface] = None)

Authentication

Method Description
login_with_credentials(login: str, password: str) Login with username and password
login_with_token(token: str) Login with API token
logout() Logout and close session (automatic with context)
is_logged_in() -> bool Check if authenticated

Execution

Method Description
execute(method: str, input_data: dict | list) -> dict | list Execute single API call
execute_endpoint_batch(method: str, requests_input_data: List[dict | list]) -> List[dict] Execute multiple calls to same endpoint
validate(method: str, input_data: dict) -> dict Validate input without execution
call(requests_list: List[Dict]) -> List[dict] Execute batch of mixed requests

Utility

Method Description
create_request(request_uuid: str, method: str, request_type: str, input_data: dict | list, ...) -> dict Create request object for batch execution
close() Close HTTP session (automatic on exit)

Best Practices

  1. Use context manager for automatic logout and cleanup:
with ApiConnector(url) as connector:
    connector.login_with_credentials("user", "pass")
    # Your API calls
    # Logout happens automatically
  1. Reuse connector - don't create new instances for each call

  2. Use batch execution for multiple requests:

# ✓ Good - single HTTP request
projects = connector.execute_endpoint_batch("project/get", inputs)

# ✗ Avoid - multiple HTTP requests
for item in items:
    connector.execute("project/get", item)
  1. Thread safety - API calls are thread-safe after login, but don't call login() from multiple threads

  2. Manual logout - only needed if not using context manager:

connector = ApiConnector(url)
connector.login_with_credentials("user", "pass")
# Your API calls
connector.logout()  # Explicit logout
# Or let it happen automatically at program exit


## License

Proprietary - Navigo Solutions

## Support

For issues or questions, contact us at **vyvoj@navigo3.com**

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

dry_apy_connector-1.0.3.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

dry_apy_connector-1.0.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file dry_apy_connector-1.0.3.tar.gz.

File metadata

  • Download URL: dry_apy_connector-1.0.3.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for dry_apy_connector-1.0.3.tar.gz
Algorithm Hash digest
SHA256 33b6291cc08be8f8e8e20142f37113723828f6a25b553283ca7dfdcdbfaa2058
MD5 d5381c23673ee221f6344d86a8716e6d
BLAKE2b-256 fc10f94eaf3c746c3063dfa8fc6805adb6082091353f84b4e18a8b5e701691e1

See more details on using hashes here.

File details

Details for the file dry_apy_connector-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for dry_apy_connector-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 23681be63e2b1fe5ec609ae7168eb2802669dccb8ebf149f2272387c71ecb758
MD5 0eae8b087ee7aca6fdc3d4734382073a
BLAKE2b-256 783e6eb4a4e10645b6310055051f288d23f58dea612d0a8bb8b09a3182767782

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