Async Python client for the Constec ERP API
Project description
Constec ERP Client
Fully auto-generated Python client library for the Constec ERP API with perfect IDE autocomplete.
This library provides type-safe, async-first access to the Constec ERP system for managing customers, suppliers, sellers, and executing custom queries.
Features
✨ Fully Auto-Generated - Always in sync with the API
🎯 Perfect Autocomplete - Full IDE support with type hints
⚡ Async-First - Built with httpx for modern async Python
🔒 Type-Safe - Complete Pydantic models for all responses
📦 Easy to Use - Clean, intuitive API wrapper
Installation
pip install constec-erp
This automatically installs the base constec library as well.
Quick Start
import asyncio
from uuid import UUID
from constec.erp import ErpClient
async def main():
async with ErpClient(base_url="https://api.example.com:8001") as client:
company_id = UUID("your-company-uuid-here")
# Get suppliers with full autocomplete support
suppliers = await client.get_suppliers(
company_id=company_id,
limit=10,
name="ACME"
)
print(f"Found {len(suppliers)} suppliers")
for supplier in suppliers:
print(f"- {supplier.pro_raz_soc} (CUIT: {supplier.pro_cuit})")
asyncio.run(main())
Why This Library?
Perfect IDE Autocomplete
When you type ErpClient( your IDE shows:
- ✅
base_url: strparameter
When you type client. you see all methods:
- ✅
get_suppliers() - ✅
get_customers() - ✅
get_sellers()
When you type client.get_suppliers( you see all parameters with types:
- ✅
company_id: UUID - ✅
limit: int = 100 - ✅
offset: int = 0 - ✅
name: Optional[str] = None - ✅
cuit: Optional[str] = None
When you access results: suppliers[0]. you see all fields:
- ✅
pro_raz_soc - ✅
pro_cuit - ✅ All supplier fields with proper types
No # type: ignore comments needed anywhere!
Usage Examples
Get Suppliers
from constec.erp import ErpClient
async with ErpClient(base_url="https://api.example.com:8001") as client:
# Get all suppliers
suppliers = await client.get_suppliers(
company_id=company_id,
limit=100
)
# Search by name
suppliers = await client.get_suppliers(
company_id=company_id,
name="Distributor",
limit=20
)
# Search by CUIT
suppliers = await client.get_suppliers(
company_id=company_id,
cuit="30-12345678-9"
)
# Pagination
suppliers = await client.get_suppliers(
company_id=company_id,
limit=50,
offset=100 # Get next page
)
Get Customers
# Get all customers
customers = await client.get_customers(
company_id=company_id,
limit=100
)
# Search by name
customers = await client.get_customers(
company_id=company_id,
name="ACME Corp"
)
# Search by CUIT
customers = await client.get_customers(
company_id=company_id,
cuit="20-98765432-1"
)
# Access customer data
for customer in customers:
print(f"Name: {customer.cli_raz_soc}")
print(f"CUIT: {customer.cli_cuit}")
print(f"Email: {customer.cli_email}")
Get Sellers
# Get all sellers
sellers = await client.get_sellers(
company_id=company_id,
limit=50
)
# Search by name
sellers = await client.get_sellers(
company_id=company_id,
name="John"
)
# Access seller data
for seller in sellers:
print(f"Code: {seller.ven_cod}")
print(f"Name: {seller.ven_desc}")
print(f"Active: {seller.ven_activo}")
Error Handling
from constec.shared import ConstecAPIError, ConstecConnectionError
try:
suppliers = await client.get_suppliers(
company_id=company_id,
limit=10
)
except ConstecConnectionError:
print("Failed to connect to API")
except ConstecAPIError as e:
print(f"API error: {e.message} (status: {e.status_code})")
Available Data Models
All response objects are fully typed Pydantic models with autocomplete support.
SupplierSchema
pro_cod: str- Supplier codepro_raz_soc: str | None- Company namepro_cuit: str | None- Tax ID (CUIT)pro_email: str | None- Email addresspro_tel: str | None- Phone numberpro_direc: str | None- Addresspro_habilitado: bool | None- Enabled statuspro_fec_mod: datetime | None- Last modified date
CustomerSchema
cli_cod: str- Customer codecli_raz_soc: str | None- Company namecli_nom_fantasia: str | None- Trade namecli_cuit: str | None- Tax ID (CUIT)cli_email: str | None- Email addresscli_tel: str | None- Phone numbercli_direc: str | None- Addresscli_loc: str | None- Locationcli_habilitado: bool | None- Enabled statuscli_fec_mod: datetime | None- Last modified date
SellerSchema
ven_cod: str- Seller codeven_desc: str | None- Name/descriptionven_email: str | None- Email addressven_tel: str | None- Phone numberven_activo: bool | None- Active statusven_fec_mod: datetime | None- Last modified date
Connection Parameters
All methods require a company_id (UUID) to identify which company's data to access.
from uuid import UUID
company_id = UUID("your-company-uuid-here")
suppliers = await client.get_suppliers(company_id=company_id)
Requirements
- Python 3.9 or higher
- httpx
- pydantic
- attrs
More Examples
Check the examples/ directory for complete working examples:
basic_usage_easy.py- Getting started with ErpClientsearch_customers.py- Customer search examplespagination.py- Working with paginated results
How It Works: Auto-Generation
This library is 100% auto-generated from the Constec ERP API's OpenAPI specification. This means:
✅ Zero manual maintenance - When the API changes, just regenerate
✅ Always in sync - Client matches the API exactly
✅ Type-safe - Full IDE autocomplete and type checking
✅ No stale documentation - Code is the source of truth
Two-Layer Architecture
The library uses a smart two-layer approach:
Layer 1: Low-Level Client (auto-generated by openapi-python-client)
- Located in
constec/erp/client.py,api/,models/ - Direct OpenAPI spec translation
- Used internally
Layer 2: User-Friendly Wrapper (auto-generated from OpenAPI spec)
- Located in
constec/erp/easy.py - Clean, simple API with perfect autocomplete
- This is what you use!
Example: What You Get
from constec.erp import ErpClient # ← Clean wrapper
async with ErpClient(base_url="...") as client: # ← Perfect autocomplete
suppliers = await client.get_suppliers( # ← Perfect autocomplete
company_id=uuid, # ← Perfect autocomplete
limit=10, # ← Perfect autocomplete
)
# Returns clean list[SupplierSchema] - no complex union types!
Regenerating the Client
If you're maintaining this library and the API changes, regenerate with:
# From the monorepo root (constec-services/)
./tools/ci/generate-erp-client.sh
This script:
- Starts the constec-erp-api server
- Fetches OpenAPI spec from
/erp/v1/openapi.json - Generates low-level client with
openapi-python-client - Generates user-friendly wrapper (
easy.py) - Creates type stubs (
.pyi) for IDE support - Stops the API server
Everything in constec/erp/ is auto-generated - never edit these files manually!
Advanced: Using the Low-Level Client
If you need direct access to the low-level auto-generated client:
from constec.erp import Client
from constec.erp.api.suppliers import list_suppliers_erp_v1_suppliers_get
client = Client(base_url="https://api.example.com:8001")
response = await list_suppliers_erp_v1_suppliers_get.asyncio_detailed(
client=client,
company_id=company_id,
)
if response.parsed:
suppliers = response.parsed.items
Note: The easy wrapper (ErpClient) is recommended for most use cases.
Contributing
This is an auto-generated library. To contribute:
- Make changes to the API (
constec-erp-api), not this client - Update the OpenAPI spec in the API
- Regenerate this client with
./tools/ci/generate-erp-client.sh - Test the changes
- Submit a PR
License
MIT License - see LICENSE file for details
Support
For issues or questions:
- Check the
examples/directory - Review the auto-generated models in
constec/erp/models/ - Check API documentation at your API server's
/erp/v1/docs
Generated from OpenAPI spec - This README documents the current auto-generated client.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file constec_erp-0.1.1.tar.gz.
File metadata
- Download URL: constec_erp-0.1.1.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e29183b25db33b178ca1262801a7c2e5dbda1c6284ddea7edca071c089850d47
|
|
| MD5 |
b9cd9d78ac12f41ce794346542165ea1
|
|
| BLAKE2b-256 |
ebbfd74b63cf7aa307249ba3203df486676c2f557576ac4d597be1b243a56f17
|
File details
Details for the file constec_erp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: constec_erp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 38.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04da74781efe57e066305657fbad6fe797407dad5eb2ac32ed0189a3a7f46751
|
|
| MD5 |
493c233dbfcc418ad76229df3e8cce02
|
|
| BLAKE2b-256 |
fc2a51ccde39dd59832110af98637edaedc0fe17f6bd68324316b2ff6c436482
|