Giter Club home page Giter Club logo

frappe-client's Introduction

Frappe Client

Simple Frappe-like Python wrapper for Frappe REST API

Install

git clone https://github.com/frappe/frappe-client
pip install -e frappe-client

API

FrappeClient has a frappe like API

Login

Login to the Frappe HTTP Server by creating a new FrappeClient object

from frappeclient import FrappeClient

conn = FrappeClient("example.com")
conn.login("[email protected]", "password")

Use token based authentication

from frappeclient import FrappeClient

client = FrappeClient("https://example.com")
client.authenticate("my_api_key", "my_api_secret")

For demonstration purposes only! Never store any credentials in your source code. Instead, you could set them as environment variables and fetch them with os.getenv().

get_list

Get a list of documents from the server

Arguments:

  • doctype
  • fields: List of fields to fetch
  • filters: Dict of filters
  • limit_start: Start at row ID (default 0)
  • limit_page_length: Page length
  • order_by: sort key and order (default is modified desc)
users = conn.get_list('User', fields = ['name', 'first_name', 'last_name'], , filters = {'user_type':'System User'})

Example of filters:

  • { "user_type": ("!=", "System User") }
  • { "creation": (">", "2020-01-01") }
  • { "name": "[email protected]" }

insert

Insert a new document to the server

Arguments:

  • doc: Document object
doc = conn.insert({
	"doctype": "Customer",
	"customer_name": "Example Co",
	"customer_type": "Company",
	"website": "example.net"
})

get_doc

Fetch a document from the server

Arguments

  • doctype
  • name
doc = conn.get_doc('Customer', 'Example Co')

get_value

Fetch a single value from the server

Arguments:

  • doctype
  • fieldname
  • filters
customer_name = conn.get_value("Customer", "name", {"website": "example.net"})

update

Update a document (if permitted)

Arguments:

  • doc: JSON document object
doc = conn.get_doc('Customer', 'Example Co')
doc['phone'] = '000000000'
conn.update(doc)

delete

Delete a document (if permitted)

Arguments:

  • doctype
  • name
conn.delete('Customer', 'Example Co')

Example

from frappeclient import FrappeClient

conn = FrappeClient("example.com", "[email protected]", "password")
new_notes = [
	{"doctype": "Note", "title": "Sing", "public": True},
	{"doctype": "Note", "title": "a", "public": True},
	{"doctype": "Note", "title": "Song", "public": True},
	{"doctype": "Note", "title": "of", "public": True},
	{"doctype": "Note", "title": "sixpence", "public": True}
]

for note in new_notes:
	print(conn.insert(note))

# get note starting with s
notes = conn.get_list('Note',
	filters={'title': ('like', 's')},
	fields=["title", "public"]
)

Example

See example.py for more info

License

MIT

frappe-client's People

Contributors

rmehta avatar ahmadpak avatar barredterra avatar thunderbottom avatar maxmorais avatar brandon-fox avatar nathando avatar surajshetty3416 avatar tillmo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.