Skip to content

Commit 277ba6d

Browse files
JesusMendozaclaude
authored andcommitted
Add CLAUDE.md for Claude Code guidance
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 08784be commit 277ba6d

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
FiscalAPI Python SDK - Official SDK for integrating with FiscalAPI, Mexico's electronic invoicing (CFDI 4.0) and fiscal services platform. Simplifies integration with SAT (Mexico's tax authority) for invoice creation, tax certificate management, and bulk downloads.
8+
9+
## Build and Publish Commands
10+
11+
```bash
12+
# Install dependencies
13+
pip install -r requirements.txt
14+
15+
# Build distribution packages
16+
pip install setuptools wheel twine build
17+
python -m build
18+
19+
# Verify packages before publishing
20+
twine check dist/*
21+
22+
# Publish to PyPI (requires PYPI_API_TOKEN)
23+
twine upload --username __token__ --password $PYPI_API_TOKEN dist/*
24+
```
25+
26+
**Version management:** Version is defined in `setup.py`. CI/CD requires the version to match the git tag (vX.Y.Z format).
27+
28+
## Architecture
29+
30+
### Service-Oriented Design with Facade Pattern
31+
32+
```
33+
FiscalApiClient (Facade)
34+
35+
├── FiscalApiSettings (Configuration)
36+
37+
└── Services (all inherit from BaseService)
38+
├── invoice_service.py → Invoice CRUD, PDF, XML, cancellation, SAT status
39+
├── people_service.py → Person/entity management
40+
├── product_service.py → Product/service catalog
41+
├── tax_file_servive.py → CSD/FIEL certificate uploads
42+
├── api_key_service.py → API key management
43+
├── catalog_service.py → SAT catalog searches
44+
└── download_*_service.py → Bulk download management
45+
```
46+
47+
**Entry Point Pattern:**
48+
```python
49+
from fiscalapi import FiscalApiClient, FiscalApiSettings
50+
51+
settings = FiscalApiSettings(api_url="...", api_key="...", tenant="...")
52+
client = FiscalApiClient(settings=settings)
53+
54+
# Access services through client
55+
client.invoices.create(invoice)
56+
client.people.get_list(page_num, page_size)
57+
```
58+
59+
### Models (Pydantic v2)
60+
61+
Located in `fiscalapi/models/`:
62+
- **common_models.py** - Base DTOs: `ApiResponse[T]`, `PagedList[T]`, `ValidationFailure`, `FiscalApiSettings`
63+
- **fiscalapi_models.py** - Domain models: `Invoice`, `Person`, `Product`, `TaxFile`, and related entities
64+
65+
**Key Pattern - Field Aliasing:** Models use Pydantic `Field(alias="...")` for API JSON field mapping. When serializing, use `by_alias=True` and `exclude_none=True`.
66+
67+
### Two Operation Modes
68+
69+
1. **By References** - Use pre-created object IDs (faster, less data transfer)
70+
2. **By Values** - Send all field data directly (self-contained, no prior setup)
71+
72+
See `examples.py` and README.md for detailed examples of both modes.
73+
74+
### Request/Response Flow
75+
76+
1. Service method receives domain object
77+
2. `BaseService.send_request()` serializes to JSON (excludes None, uses aliases)
78+
3. URL constructed: `{base_url}/api/{version}/{endpoint}`
79+
4. Headers added: `X-TENANT-KEY`, `X-API-KEY`, `X-TIME-ZONE`
80+
5. Response deserialized to `ApiResponse[T]` with typed data
81+
82+
### SSL Handling
83+
84+
- Development (localhost/127.0.0.1): SSL verification disabled
85+
- Production: Uses certifi certificate store
86+
87+
## Key Files
88+
89+
- `fiscalapi/__init__.py` - Central exports for all models and services
90+
- `fiscalapi/services/base_service.py` - HTTP client, serialization, response handling
91+
- `fiscalapi/services/fiscalapi_client.py` - Main client facade
92+
- `examples.py` - 3600+ lines of usage examples (commented out)
93+
- `setup.py` - Package metadata, version, and dependencies
94+
95+
## Dependencies
96+
97+
- Python >= 3.7
98+
- pydantic >= 2.0.0 (validation & serialization)
99+
- requests >= 2.0.0 (HTTP client)
100+
- email_validator >= 2.2.0
101+
102+
## External Resources
103+
104+
- API Documentation: https://docs.fiscalapi.com
105+
- Test Certificates: https://docs.fiscalapi.com/recursos/descargas
106+
- Postman Collection: Available in docs

0 commit comments

Comments
 (0)