Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ERPNext Authentication Credentials Example
ERPNEXT_USERNAME=your_username_or_email
ERPNEXT_PASSWORD=your_password
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ share/python-wheels/
*.egg
MANIFEST

# Virtual environments
# Environment variables and secrets
.env
.env.*
!.env.example

# Virtual environments
.venv
env/
venv/
Expand All @@ -47,3 +51,8 @@ venv.bak/
.pytest_cache/
.coverage
htmlcov/

# Linter and type checker caches
.ruff_cache/
.mypy_cache/

46 changes: 32 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
# ERPNext Client

A simple Python client for ERPNext. Use this to access the data without needing to create raw HTTP requests.
A simple Python client for ERPNext. Use this to access data without needing to create raw HTTP requests.

## Installation

This package uses Poetry for dependency management. Install it using:
This package uses Poetry for dependency management. Install it in another project using:

```sh
poetry add git+https://github.com/your-username/csa-erp-client.git

poetry add git+https://github.com/Agriworks/erpnext_client.git
```

## Setup & Running

1. **Install dependencies**:
```sh
poetry install
```

2. **Configure environment credentials**:
```sh
cp .env.example .env
```
Add your `ERPNEXT_USERNAME` and `ERPNEXT_PASSWORD` in `.env`.

3. **Run the example script**:
```sh
poetry run python example.py
```

## Usage

Here's a simple example of how to use the ERPNext client:

```py
import os
from dotenv import load_dotenv
from erp_client.erp_next_client import ERPNextClient

load_dotenv()

# Initialize the client with your ERPNext instance URL
client = ERPNextClient(base_url="https://your-erp-instance.com")
client = ERPNextClient(base_url="http://erp.csa-india.org")

# Login with your credentials
client.login(username="your_username", password="your_password")
client.login(
username=os.getenv("ERPNEXT_USERNAME"),
password=os.getenv("ERPNEXT_PASSWORD")
)

# Fetch a dataset
dataset_id = "Your Dataset Name"
dataset_id = "CC Daily Reports"
dataset = client.get_dataset(dataset_id)
print(f"Dataset contents:\n{dataset.head()}")

Expand All @@ -36,18 +60,12 @@ print(f"Synced data:\n{sync_data.head()}")
# Get dataset schema
schema = client.get_dataset_schema(dataset_id)
print(f"Dataset schema: {schema}")

```

## Features
- Simple authentication with ERPNext instance
- Fetch complete datasets as pandas DataFrames
- Support for child tables and query reports
- Synchronize and pull datasets from a specific index
- Retrieve dataset schemas
- Built-in session management


# Items in Progress

- Development a sync protocol to sync data from ERPNext to the client

4 changes: 2 additions & 2 deletions erp_client/erp_next_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional
import pandas as pd
import requests
from .data_shaper import DataShaper, reshape_dataset, to_dataframe
from .data_shaper import DataShaper


class ERPNextClient:
Expand Down
19 changes: 13 additions & 6 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import requests
import pandas as pd
from erp_client.erp_next_client import ERPNextClient
import os
from dotenv import load_dotenv
from erp_client import ERPNextClient

# Load environment variables from .env file
load_dotenv()


if __name__ == "__main__":
Expand All @@ -11,8 +13,13 @@
- Query Reports (e.g. 'Stock Balance')
"""
client = ERPNextClient(base_url="http://erp.csa-india.org")
username = "[EMAIL_ADDRESS]"
password = "[PASSWORD]"
username = os.getenv("ERPNEXT_USERNAME")
password = os.getenv("ERPNEXT_PASSWORD")

if not username or not password:
print("✗ Missing ERPNEXT_USERNAME or ERPNEXT_PASSWORD in .env file.")
print(" Please create a .env file based on .env.example with valid credentials.")
exit(1)

errors = []

Expand Down
Loading