Python integrations (local run/tests)

Hello there!
I need to provide a integration python script (bot) for DAML app. Is it a any way to run and test application on local machine?

Hi Anton. The supported way of doing this is running a sandbox instance (daml start) on your local machine, and then sending commands to it via the JSON API

You can also consider writing scripts natively in daml script

and these can then be run using daml test; however, this can’t perform any off-ledger actions (e.g. read/write from a file). You’d need to code those in Pyhon.

Hope that helps!

1 Like

Thank you Luciano, but I think I was not clear enough. I need to provide script which make API calls to another web service, and after that store respond data to the daml. I tried to use example this example just to run it locally and after that change it for my purpose. When I try to use make all command I have an error - make: ddit: Command not found

To avoid confusion, can you just confirm whether you are trying to port a project hosted on daml hub to a local project?

Or alternatively, is this an entirely new app you are writing from scratch, and you want to develop it locally on your machine?

[edit] The reason I’m asking this is that the example you cite uses an API that is no longer official supported (GitHub - digital-asset/dazl-client: dazl Ledger API client), but used internally by hub. At present, we suggest your use the JSON API instead.

I’m building a new app from scratch. Thank you but, I don’t think the API way will be corresponding for me, because the general demand is make integration with async python bots.

Blockquote To avoid confusion, can you just confirm whether you are trying to port a project hosted on daml hub to a local project?

It’s a local project

In this case, I strongly suggest you avoid using the example you cited. It uses an old library, dazl, which is considerably different from the JSON API. It also relies on some tooling which is used internally for Hub. The JSON API is much better documented; you can use your choice of Python JSON library to talk to the ledger.

As long as your choice of network stack is asynchronous, your bots should be asynchronous. The JSON API is not a client library in itself; it’s just a specification of the message format.

@Anton_Aksyonov ,

If you’re running Python code locally, you have a few options that are available. The first, as @Luciano mentioned, is the use of the HTTP JSON API. This is a layer that sits atop the ledger’s native api (gRPC) and makes it available via standard HTTP requests in a JSON format. This allows you to use standard HTTP client libraries to query the ledger for current contract data, request event streams from the ledger, and issue commands to manipulate contracts on the ledger.

Generally speaking, this is where we advise people to begin when they are considering ways to interact with a ledger. HTTP and JSON are both widely supported in many languages (of course including Python), and this is an efficient way to access most of the ledger’s functionality.

However, there are other ways of accessing the ledger, including the Dazl client library. Dazl predates the HTTP JSON API I mention above, is still receiving improvements, and has a few capabilities the HTTP JSON API does not. (Specifically, Dazl can enable access to historical contracts that have already been archived.)

While Dazl is not specific to Daml Hub, we do use it extensively within Daml Hub, and it how both Python Bots and Integrations are written within Daml Hub. If and when you get the point where you’re considering Daml Hub as your platform, feel free to reach out and we’ll be happy to discuss the specifics of this hosting in more detail.

In the meantime, happy to answer any further questions about the specific integrations you’re developing.


1 Like

One other detail I can add is that the Slack Integration example you’re looking at is built specifically for Daml Hub at the moment. It can run locally, but there is specific tooling you need to install to do so. (The ddit command you’re missing in this error.) Details on that are here, although this is not a recommended way to run ledger integrations locally, unless you are specifically developing a Daml Hub integration.

GitHub - digital-asset/daml-dit-ddit