moy-nalog-api 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- moy_nalog_api-1.0.4/.gitignore +46 -0
- moy_nalog_api-1.0.4/CHANGELOG.md +64 -0
- moy_nalog_api-1.0.4/CLAUDE.md +61 -0
- moy_nalog_api-1.0.4/LICENSE +21 -0
- moy_nalog_api-1.0.4/PKG-INFO +608 -0
- moy_nalog_api-1.0.4/README.md +568 -0
- moy_nalog_api-1.0.4/README.ru.md +568 -0
- moy_nalog_api-1.0.4/examples/async_example.py +104 -0
- moy_nalog_api-1.0.4/examples/sms_auth.py +58 -0
- moy_nalog_api-1.0.4/examples/sync_example.py +47 -0
- moy_nalog_api-1.0.4/meta.yaml +46 -0
- moy_nalog_api-1.0.4/moy_nalog/__init__.py +88 -0
- moy_nalog_api-1.0.4/moy_nalog/client.py +1189 -0
- moy_nalog_api-1.0.4/moy_nalog/enums.py +38 -0
- moy_nalog_api-1.0.4/moy_nalog/exceptions.py +68 -0
- moy_nalog_api-1.0.4/moy_nalog/models.py +180 -0
- moy_nalog_api-1.0.4/pyproject.toml +105 -0
- moy_nalog_api-1.0.4/scripts/integration_test.py +882 -0
- moy_nalog_api-1.0.4/tests/__init__.py +1 -0
- moy_nalog_api-1.0.4/tests/test_client.py +111 -0
- moy_nalog_api-1.0.4/tests/test_models.py +152 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
.eggs/
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
venv/
|
|
15
|
+
.venv/
|
|
16
|
+
env/
|
|
17
|
+
|
|
18
|
+
# Environment
|
|
19
|
+
.env
|
|
20
|
+
.env.local
|
|
21
|
+
session.json
|
|
22
|
+
*.pkl
|
|
23
|
+
|
|
24
|
+
# IDE
|
|
25
|
+
.idea/
|
|
26
|
+
.vscode/
|
|
27
|
+
*.swp
|
|
28
|
+
*.swo
|
|
29
|
+
.DS_Store
|
|
30
|
+
|
|
31
|
+
# Testing
|
|
32
|
+
.pytest_cache/
|
|
33
|
+
.coverage
|
|
34
|
+
htmlcov/
|
|
35
|
+
.tox/
|
|
36
|
+
.mypy_cache/
|
|
37
|
+
.ruff_cache/
|
|
38
|
+
test_output/
|
|
39
|
+
|
|
40
|
+
# Misc
|
|
41
|
+
*.log
|
|
42
|
+
Thumbs.db
|
|
43
|
+
uv.lock
|
|
44
|
+
/.serena/
|
|
45
|
+
/.cursor/
|
|
46
|
+
/.claude/
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.4] - 2026-01-16
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- New `device_id` property on both `MoyNalogClient` and `MoyNalogClientSync` for accessing the device identifier
|
|
12
|
+
- New `download_receipt_raw()` method for downloading receipt as raw bytes with retry support
|
|
13
|
+
- New `user_agent` parameter to customize User-Agent header in requests
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Improved sync client cleanup with `__del__` method and `_closed` flag to prevent resource leaks
|
|
17
|
+
- Better error handling: safe JSON parsing, UUID validation for receipt IDs
|
|
18
|
+
- Internal refactoring: extracted `_normalize_phone`, `_parse_datetime`, `_validate_receipt_uuid` helper methods
|
|
19
|
+
|
|
20
|
+
## [1.0.3] - 2025-12-26
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- `is_token_expired` now returns `True` when token expiration time is unknown (previously returned `False`, which could cause `TokenExpiredError` on requests with stale tokens)
|
|
24
|
+
- Added automatic retry with token refresh on 401 responses - if server returns 401, client will attempt to refresh the token and retry the request once before raising `TokenExpiredError`
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- Token refresh is now more aggressive: tokens with unknown expiration time are treated as expired to ensure proactive refresh
|
|
28
|
+
|
|
29
|
+
## [1.0.2] - 2025-12-15
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
- Proxy server support for all API requests
|
|
33
|
+
- HTTP/HTTPS proxy (works out of the box)
|
|
34
|
+
- SOCKS4/SOCKS5 proxy (requires `pip install moy-nalog-api[socks]`)
|
|
35
|
+
- Proxy authentication support (user:password in URL)
|
|
36
|
+
- New `proxy` parameter in `MoyNalogClient` and `MoyNalogClientSync`
|
|
37
|
+
- New optional dependency `[socks]` for SOCKS proxy support (httpx-socks)
|
|
38
|
+
|
|
39
|
+
## [1.0.1] - 2025-12-14
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- README cross-links for PyPI display
|
|
43
|
+
- Missing properties and methods in sync client
|
|
44
|
+
|
|
45
|
+
## [1.0.0] - 2025-12-14
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
- Initial release
|
|
49
|
+
- Async client (`MoyNalogClient`) with httpx
|
|
50
|
+
- Sync wrapper (`MoyNalogClientSync`) for non-async code
|
|
51
|
+
- Password authentication via nalog.ru credentials
|
|
52
|
+
- SMS authentication (request code + verify)
|
|
53
|
+
- Automatic token refresh before expiration
|
|
54
|
+
- Session persistence to JSON file
|
|
55
|
+
- Retry with exponential backoff
|
|
56
|
+
- Full Pydantic v2 validation
|
|
57
|
+
- Receipt creation (single and multiple items)
|
|
58
|
+
- Receipt cancellation with reason (refund/mistake)
|
|
59
|
+
- Income list with pagination and filtering
|
|
60
|
+
- User profile retrieval
|
|
61
|
+
- All client types support (individual, legal entity, foreign)
|
|
62
|
+
- Payment types (cash, wire transfer)
|
|
63
|
+
- Complete type hints (mypy compatible)
|
|
64
|
+
- Comprehensive documentation in English and Russian
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
Python client library for the Russian self-employed tax service API (lknpd.nalog.ru / "Moy Nalog"). Provides async and sync interfaces for authentication, receipt creation, and income management.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Install dependencies
|
|
13
|
+
pip install -e ".[dev]"
|
|
14
|
+
|
|
15
|
+
# Run all tests
|
|
16
|
+
pytest
|
|
17
|
+
|
|
18
|
+
# Run single test file
|
|
19
|
+
pytest tests/test_client.py
|
|
20
|
+
|
|
21
|
+
# Run with coverage
|
|
22
|
+
pytest --cov=moy_nalog
|
|
23
|
+
|
|
24
|
+
# Linting
|
|
25
|
+
ruff check .
|
|
26
|
+
|
|
27
|
+
# Type checking
|
|
28
|
+
mypy moy_nalog
|
|
29
|
+
|
|
30
|
+
# Build package
|
|
31
|
+
python -m build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Architecture
|
|
35
|
+
|
|
36
|
+
### Module Structure (`moy_nalog/`)
|
|
37
|
+
|
|
38
|
+
- `client.py` - Main `MoyNalogClient` (async) and `MoyNalogClientSync` (sync wrapper) classes. Contains all API interaction logic, authentication, session management, and retry logic with exponential backoff.
|
|
39
|
+
- `models.py` - Pydantic v2 models for API requests/responses (`ServiceItem`, `Client`, `Receipt`, `UserProfile`, `IncomeList`, `SessionData`, etc.)
|
|
40
|
+
- `exceptions.py` - Typed exception hierarchy rooted at `MoyNalogError`
|
|
41
|
+
- `enums.py` - `IncomeType`, `PaymentType`, `CancelReason` enums
|
|
42
|
+
|
|
43
|
+
### Key Design Patterns
|
|
44
|
+
|
|
45
|
+
**Dual Client Architecture**: `MoyNalogClientSync` wraps `MoyNalogClient` by creating its own event loop and delegating all async methods via `run_until_complete()`.
|
|
46
|
+
|
|
47
|
+
**Session Persistence**: Optional JSON file-based session storage. Tokens are saved on `close()` and loaded on client initialization when `session_file` is provided.
|
|
48
|
+
|
|
49
|
+
**Auto Token Refresh**: Before authenticated requests, checks `is_token_expired` (with 60s margin) and auto-refreshes via `_do_refresh_token()`.
|
|
50
|
+
|
|
51
|
+
**Proxy Support**: HTTP/HTTPS proxies via native httpx, SOCKS proxies via optional `httpx-socks` dependency.
|
|
52
|
+
|
|
53
|
+
### API Endpoints
|
|
54
|
+
|
|
55
|
+
The client interacts with two API versions:
|
|
56
|
+
- `API_URL_V1 = "https://lknpd.nalog.ru/api/v1"` - most endpoints
|
|
57
|
+
- `API_URL_V2 = "https://lknpd.nalog.ru/api/v2"` - SMS start endpoint only
|
|
58
|
+
|
|
59
|
+
### Test Configuration
|
|
60
|
+
|
|
61
|
+
Tests use `pytest-asyncio` with `asyncio_mode = "auto"` in pyproject.toml. The `tests/test_models.py` tests Pydantic model validation; `tests/test_client.py` tests client initialization and validation without making real API calls.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kirill Nikulin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|