Skip to main content

A lightweight Python client for connecting and interacting with Frappe instances

Project description

frappe-connector

A lightweight Python client for connecting and interacting with Frappe instances.

Installation

pip install frappe-connector

Authentication

Session login (username + password)

from frappe_connector import FrappeConnector

client = FrappeConnector(
    "https://erp.example.com",
    username="admin",
    password="secret",
)

Token login (API key + secret)

client = FrappeConnector(
    "https://erp.example.com",
    api_key="your_api_key",
    api_secret="your_api_secret",
)

Context manager (auto-logout)

with FrappeConnector("https://erp.example.com", username="admin", password="secret") as client:
    records = client.get_list("Customer")

CRUD Operations

get_list — fetch multiple records

customers = client.get_list(
    "Customer",
    fields=["name", "customer_name", "email_id"],
    filters={"status": "Active"},
    offset=0,
    page_size=20,
    order_by="creation desc",
)

get_doc — fetch a single document

# by name
customer = client.get_doc("Customer", name="CUST-00001")

# by filter
customer = client.get_doc(
    "Customer",
    filters={"customer_name": "Acme Corp"},
    fields=["name", "customer_name", "email_id"],
)

create_doc — insert a new document

new_customer = client.create_doc({
    "doctype": "Customer",
    "customer_name": "Globex Corporation",
    "customer_type": "Company",
    "customer_group": "Commercial",
    "territory": "All Territories",
})

update_doc — update an existing document

updated = client.update_doc({
    "doctype": "Customer",
    "name": "CUST-00001",
    "phone": "+977-9800000000",
})

delete_doc — delete a document

client.delete_doc("Customer", "CUST-99999")

rename_doc — rename a document

client.rename_doc("Customer", old_name="CUST-OLD", new_name="CUST-NEW")

submit_doc — submit a document

client.submit_doc([{"doctype": "Sales Invoice", "name": "SINV-00001"}])

API Method Calls

get_api — call a whitelisted GET method

result = client.get_api("myapp.api.get_summary", params={"year": 2025})

post_api — call a whitelisted POST method

result = client.post_api("myapp.api.process_order", params={"order_id": "ORD-001"})

Error Handling

All exceptions inherit from FrappeException, so you can catch broadly or specifically.

from frappe_connector import FrappeConnector, LoginFailedError, ServerError, FrappeException

try:
    client = FrappeConnector("https://erp.example.com", username="admin", password="wrong")
except LoginFailedError as e:
    print(e)  # "Invalid credentials or login rejected by server."

try:
    client.get_doc("Customer", "CUST-001")
except ServerError as e:
    print(e.server_traceback)  # full traceback from Frappe
    print(e.response)          # raw requests.Response object
except FrappeException as e:
    print(e)
Exception When raised
FrappeException Base class for all library errors
LoginFailedError Credentials rejected by the server
ServerError Server returned an exception in the response body

Closing the session

client.close()  # logs out from the server

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

frappe_connector-0.1.1.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

frappe_connector-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file frappe_connector-0.1.1.tar.gz.

File metadata

  • Download URL: frappe_connector-0.1.1.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for frappe_connector-0.1.1.tar.gz
Algorithm Hash digest
SHA256 65a3f11e6a9373bca4dd4134388ab383d04b270cd42af46a2f02c680b718a186
MD5 75d5af17fc4023ac94a5f8f75aefbfe3
BLAKE2b-256 4ada9c3f44199882a65db9fd6f377585579f922e5b9e395a83eb2d3a19ee6385

See more details on using hashes here.

File details

Details for the file frappe_connector-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: frappe_connector-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for frappe_connector-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db3ca332a6e8e7b2c17fceabe89e6ec88f11f305a60a26f618afaaedea2d5dbe
MD5 3f21e5d5ae7a7d2442f07924db148b59
BLAKE2b-256 1ade459eb42e8b0c9e0a95cd56510226f42002f06805f0545ffede6bf2f1d80e

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