A client library for accessing Credmark Gateway
Project description
Credmark
An SDK for accessing Credmark Gateway
Installation
Install using pip:
pip install credmark
Usage
First, create an authenticated client. In order to access the API, you will need a key. Information about getting a key is available in our API setup guide.
from credmark import AuthenticatedClient
client = AuthenticatedClient(api_key="<Your API Key>")
Now call your endpoint and use your models:
from credmark.models import TokenMetadataResponse
from credmark.token_api import get_token_metadata
from credmark.types import Response
my_data: TokenMetadataResponse = get_token_metadata.sync(1, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", client=client)
# or if you need more info (e.g. status_code)
response: Response[TokenMetadataResponse] = get_token_metadata.sync(1, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", client=client)
Or do the same thing with an async version:
from credmark.models import TokenMetadataResponse
from credmark.token_api import get_token_metadata
from credmark.types import Response
my_data: TokenMetadataResponse = await get_token_metadata.asyncio(1, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", client=client)
response: Response[TokenMetadataResponse] = await get_token_metadata.asyncio_detailed(1, "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9", client=client)
Run a model
You can run a model using DeFi API:
from credmark.defi_api import run_model
from credmark.models import RunModelDto
async def run_model_example():
response = await run_model.asyncio(
client=client,
json_body=RunModelDto(
chain_id=1,
block_number="latest",
slug="price.quote",
input={"base": {"symbol": "AAVsdadE"}}
),
)
if response.error:
print(response.error)
return
price = response.output['price']
print(price)
Available APIs
Things to know:
-
Every path/method combo has four functions:
sync
: Blocking request that returns parsed data (if successful) orNone
sync_detailed
: Blocking request that always returns aRequest
, optionally withparsed
set if the request was successful.asyncio
: Likesync
but async instead of blockingasyncio_detailed
: Likesync_detailed
but async instead of blocking
-
All path/query params, and bodies become method arguments.
Advanced Usage
By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
client = AuthenticatedClient(
base_url="https://internal_api.example.com",
api_key="SuperSecretToken",
verify_ssl="/path/to/certificate_bundle.pem",
)
You can also disable certificate validation altogether, but beware that this is a security risk.
client = AuthenticatedClient(
base_url="https://internal_api.example.com",
api_key="SuperSecretToken",
verify_ssl=False
)
There are more settings on the generated Client
class which let you control more runtime behavior, check out the docstring on that class for more info.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.