Autocode Standard Library Python Bindings
The `lib` library provides basic Python bindings for interacting with the Autocode standard library, enabling users to call functions from deployed Autocode services. It serves as a zero-dependency interface to execute StdLib functions and automatically generates Python SDKs for services deployed to Autocode. The current version is 4.0.0, and the project is actively maintained.
Warnings
- breaking Upgrading from `lib` v3.x to v4.x may introduce breaking changes. While specific migration guides were not found in the immediate search results, major version bumps in semantic versioning typically indicate incompatible API changes.
- gotcha All interactions with Autocode services via `lib` are network calls and can result in `RuntimeError` due to issues like network failures, invalid service paths, or errors within the called Autocode function. It is crucial to implement robust error handling.
- gotcha While the `lib` Python library itself has zero Python dependencies, its core utility relies on the Autocode platform. To build, deploy, or manage the services you call with `lib`, you will need to use the Autocode CLI and have an Autocode account.
- gotcha The `lib` library documentation mentions support for Python 2.x and 3.x. However, active development and the modern ecosystem typically prioritize Python 3.x. Users on older Python 2.x environments should thoroughly test compatibility, as future updates might implicitly favor Python 3.x practices or drop older support.
Install
-
pip install lib
Imports
- lib
from lib import lib
Quickstart
from lib import lib
import os
# Replace 'yourUsername' and 'yourService' with actual Autocode service details
# and ensure the function 'myFunction' exists on that service.
# The 'key' and 'value' parameters are example arguments for the function.
# In a real scenario, you might interact with environment variables for API keys or service names.
# For example, if your service requires an API key, you might pass it as an argument:
# result = lib.yourUsername.yourService.myFunction(api_key=os.environ.get('AUTOCODE_API_KEY', ''))
try:
# Example: Call a function from a user's service
# This assumes 'yourUsername' has a service named 'yourService' with a default function
# that accepts a 'key' parameter.
result = lib.yourUsername.yourService(key='example_value')
print(f"Service call successful: {result}")
# Example: Call a specific function within a service, specifying environment
# result_dev = lib.yourUsername.yourService.myFunction['@dev'](another_key='test')
# print(f"Dev service call successful: {result_dev}")
except RuntimeError as err:
print(f"Error calling Autocode service: {err}")
except Exception as e:
print(f"An unexpected error occurred: {e}")