Skip to main content

The official Python library for the mechanix API

Project description

Mechanix Python API

PyPI version

The Mechanix Python library provides convenient access to the Mechanix REST API from any Python 3.8+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients.

Documentation

Installation

pip install --pre mechanix

Usage

from mechanix import Mechanix

client = Mechanix()

search_response_bundle = client.tools.search.web(
    query="Common organelles within a human eukaryote",
)
print(search_response_bundle.llm)

While you can provide an api_key keyword argument, we recommend using python-dotenv to add MECHANIX_API_KEY="My API Key" to your .env file so that your API Key is not stored in source control.

Async usage

Simply import AsyncMechanix instead of Mechanix and use await with each API call:

import asyncio
from mechanix import AsyncMechanix

client = AsyncMechanix()


async def main() -> None:
    search_response_bundle = await client.tools.search.web(
        query="Common organelles within a human eukaryote",
    )
    print(search_response_bundle.llm)


asyncio.run(main())

Functionality between the synchronous and asynchronous clients is otherwise identical.

Handling errors

When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of mechanix.APIConnectionError is raised.

When the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of mechanix.APIStatusError is raised, containing status_code and response properties.

All errors inherit from mechanix.APIError.

import mechanix
from mechanix import Mechanix

client = Mechanix()

try:
    client.tools.search.web(
        query="Common organelles within a human eukaryote",
    )
except mechanix.APIConnectionError as e:
    print("The server could not be reached")
    print(e.__cause__)  # an underlying Exception, likely raised within httpx.
except mechanix.RateLimitError as e:
    print("A 429 status code was received; we should back off a bit.")
except mechanix.APIStatusError as e:
    print("Another non-200-range status code was received")
    print(e.status_code)
    print(e.response)

Error codes are as followed:

Status Code Error Type
400 BadRequestError
401 AuthenticationError
403 PermissionDeniedError
404 NotFoundError
422 UnprocessableEntityError
429 RateLimitError
>=500 InternalServerError
N/A APIConnectionError

Credits

This API library is generated with Stainless.

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

mechanix-0.1.0a5.tar.gz (84.6 kB view details)

Uploaded Source

Built Distribution

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

mechanix-0.1.0a5-py3-none-any.whl (74.9 kB view details)

Uploaded Python 3

File details

Details for the file mechanix-0.1.0a5.tar.gz.

File metadata

  • Download URL: mechanix-0.1.0a5.tar.gz
  • Upload date:
  • Size: 84.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for mechanix-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 07d70ad80bfd6521971c4eab705a8c0a4c85443bfcb03934f54206a81be7bb37
MD5 72cfe5e5f2168ff420fd08b7d4e33e0d
BLAKE2b-256 4247e30351404af70d36fccc69eaeaf3a6ce69a991016186c2bdff18c8d450f6

See more details on using hashes here.

File details

Details for the file mechanix-0.1.0a5-py3-none-any.whl.

File metadata

  • Download URL: mechanix-0.1.0a5-py3-none-any.whl
  • Upload date:
  • Size: 74.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for mechanix-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 66f3a9363743bb07a16d8bc8dc69ccce40384016a053d36bbc1d998db030bc09
MD5 839203659c13b1adb9828f28a68c951c
BLAKE2b-256 4f5f901f23030a10625a0bbc26ff4a68be4fb0fcba1c03c66ae3d5f745c3782e

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