Skip to main content

A Python API module designed to run queries on Nectar

Project description

PYTHON NECTAR MODULE

1. Install the module

pip install nectarpy

• If you see an error, try pip3 install nectarpy instead.

• Wait until the installation finishes. You should see a message that it was installed successfully.

2. Use the module in Python

The library exports two role-specific clients:

Data Owner (DO): Nectar
Data Analyst (DA): NectarClient

Your API_SECRET is your API account private key (hex string). It may start with 0x.

Supported mode values are: moonbeam (default), moonbase, localhost.

Data Owner (DO)

from nectarpy import Nectar

API_SECRET = "<api-secret>"
nectar = Nectar(API_SECRET, mode="moonbeam")

Role enforcement: Nectar only works for accounts with the DO role. If your API account does not have the DO role, initialization will raise a RuntimeError.

Data Analyst (DA)

from nectarpy import NectarClient

API_SECRET = "<api-secret>"
nectar_client = NectarClient(API_SECRET, mode="moonbeam")

Role enforcement: NectarClient only works for accounts with the DA role. If your API account does not have the DA role, initialization will raise a RuntimeError.

3. Common operations

Below are minimal, end-to-end examples for the primary APIs exposed by the library.

Data Owner (DO): policies & buckets

from nectarpy import Nectar

API_SECRET = "<api-secret>"
nectar = Nectar(API_SECRET, mode="moonbeam")

# 1) Create a policy
policy_id = nectar.add_policy(
	allowed_categories=["*"],
	allowed_addresses=["0x0000000000000000000000000000000000000000"],
	allowed_columns=["*"],
	valid_days=30,
	usd_price=0.01,
)

# 2) Create a bucket that references one or more policies
bucket_id = nectar.add_bucket(
	policy_ids=[policy_id],
	use_allowlists=[True],
	data_format="std1",
	node_address="tls://<ip-address>:5229",
)

Data Analyst (DA): run a BYOC query

from nectarpy import NectarClient

API_SECRET = "<api-secret>"
nectar_client = NectarClient(API_SECRET, mode="moonbeam")

def count_func():
	import pandas as pd
	df = pd.read_csv("/app/data/worker-data.csv")
	return {"count": len(df)}

# 1) Prepare bucket/policy references (provided by the DO)
bucket_ids = ["<bucket-id>"]
policy_indexes = [0]

# 2) Execute the query
result = nectar_client.byoc_query(
	pre_compute_func=None,
	main_func=count_func,
	is_separate_data=False,
	bucket_ids=bucket_ids,
	policy_indexes=policy_indexes,
)

print(result)

4. Detailed Documentation in your Nectar account

• Data Analyst role: API document for Data Analyst

• Data Owner role: API document for Data Owner

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

nectarpy-0.15.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

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

nectarpy-0.15.0-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file nectarpy-0.15.0.tar.gz.

File metadata

  • Download URL: nectarpy-0.15.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for nectarpy-0.15.0.tar.gz
Algorithm Hash digest
SHA256 f742bc16e01ce1ab3fddadb8fb051ab30d39743b897cb0e72bbbde826a788121
MD5 4b188ea21cd25d34bb15a2fc96c55e09
BLAKE2b-256 f0f2dbbf4aece5a69fb39dbcb4957d141628f64c791ea293c5e2861ff919e011

See more details on using hashes here.

File details

Details for the file nectarpy-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: nectarpy-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 45.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for nectarpy-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e4a928819f813a44e0d288895cf18e77056adecc412a352d8b1ef6a1179572d
MD5 f993007a4170558c5a5cfcc082e522d0
BLAKE2b-256 1cfc8cf3c66807c50b90879a75a6ce8ca1a9d9aaaecb3adfeee315e4b55a061b

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