Michelson script wrappers

Contract code

class pytezos.michelson.contract.Contract(code: list)[source]

Represents a Michelson script.

classmethod from_file(path)[source]

Create contract from michelson source code stored in file.

Parameters

path – Path to the .tz file

Return type

Contract

classmethod from_micheline(code)[source]

Create contract from micheline expression.

Parameters

code – [{‘prim’: ‘parameter’}, {‘prim’: ‘storage’}, {‘prim’: ‘code’}]

Return type

Contract

classmethod from_michelson(text)[source]

Create contract from michelson source code.

Parameters

text – Michelson source code.

Return type

Contract

property parameter

Returns parameter section wrapper.

Return type

ContractParameter

save_file(path, overwrite=False)[source]

Save Michelson code to file.

Parameters
  • path – Output path

  • overwrite – Default is False

script(storage=None, original=True) → dict[source]

Generate script for contract origination.

Parameters
  • storage – Python object, leave None to generate empty

  • original – Keep the original code (initialized), which is default. Otherwise factory-specific changes may applied, e.g. different annotations

Returns

{“code”: $Micheline, “storage”: $Micheline}

property storage

Returns storage section wrapper.

Return type

ContractStorage

property text

Get Michelson formatted code.

Implied interface

class pytezos.standards.non_fungible_token.NonFungibleTokenImpl(code: list)[source]

This is an example of how to force contract interface (in case it’s not annotated)

classmethod from_file(path)

Create contract from michelson source code stored in file.

Parameters

path – Path to the .tz file

Return type

Contract

classmethod from_micheline(code)

Create contract from micheline expression.

Parameters

code – [{‘prim’: ‘parameter’}, {‘prim’: ‘storage’}, {‘prim’: ‘code’}]

Return type

Contract

classmethod from_michelson(text)

Create contract from michelson source code.

Parameters

text – Michelson source code.

Return type

Contract

property parameter

Returns parameter section wrapper.

Return type

ContractParameter

save_file(path, overwrite=False)

Save Michelson code to file.

Parameters
  • path – Output path

  • overwrite – Default is False

script(storage=None, original=True) → dict

Generate script for contract origination.

Parameters
  • storage – Python object, leave None to generate empty

  • original – Keep the original code (initialized), which is default. Otherwise factory-specific changes may applied, e.g. different annotations

Returns

{“code”: $Micheline, “storage”: $Micheline}

property storage

Returns storage section wrapper.

Return type

ContractStorage

property text

Get Michelson formatted code.

Parameter section

class pytezos.michelson.contract.ContractParameter(section)[source]

Encapsulates the parameter section of a Michelson script.

decode(data)[source]

Convert Micheline data into Python object using internal schema.

Parameters

data – Micheline expression or Michelson string or {entrypoint: “string”, value: “expression”}

Returns

Python object

encode(data, entrypoint=None)[source]

Convert Python object to Micheline expression using internal schema.

Parameters
  • data – Python object

  • entrypoint – Force entrypoint

Returns

object

entries(default='call')[source]

Get list of entrypoints: names and docstrings.

Parameters

default – Name of the single entrypoint

Returns

[(“name”, “docstring”), …]

Storage section

class pytezos.michelson.contract.ContractStorage(section)[source]

Encapsulates the storage section of a Michelson script.

big_map_decode(value, big_map_id=None)[source]

Convert big_map_get result into a Python object.

Parameters
  • value – Micheline expression for a BigMap entry (since Babylon you can have more than one BigMap at arbitrary position)

  • big_map_id – BigMap pointer (integer)

Returns

object

big_map_diff_decode(diff: list) → dict[source]

Convert big_map_diff from operation_result section into Python objects.

Parameters

diff – [{“key”: $micheline, “value”: $micheline}, …]

Returns

{“path/to/big/map”: {“key”: “value”}} for Babylon; {“key”: “value”} for old contracts

big_map_diff_encode(big_map: dict) → list[source]

Convert Python representation of BigMap (dict) into big_map_diff.

Parameters

big_map – { $key: $micheline, … }

Returns

[{“key”: $micheline, “value”: $micheline}, … ]

big_map_id(big_map_path) → int[source]

Get Big_map id by JSON path

Parameters

big_map_path – JSON path

Return type

int

big_map_init(data)[source]

Initialize big_map_id <-> JSON path mapping (since Babylon).

Parameters

data – Micheline expression (raw contract storage)

big_map_query(path)[source]

Construct a query for big_map_get request.

Parameters

path – BigMap key, string, int, or hex-string (since Babylon you can have more than one BigMap at arbitrary position)

Return type

dict

decode(data)[source]

Convert Micheline data into Python object using internal schema.

Parameters

data – Micheline expression or Michelson string

Returns

object

default(root='0')[source]

Try to generate empty storage, returns Micheline expression.

Parameters

root – binary path to start from, default is ‘0’

Returns

object

encode(data)[source]

Convert Python object to Micheline expression using internal schema.

Parameters

data – Python object

Returns

object