NexusPHP API Client - A Python client for interacting with NexusPHP forum API
Project description
NexusPHP API Client
NexusPHP API Client - A Python client for interacting with NexusPHP forum API.
Project Structure
nexusphp_api/
├── api/ # API data models
│ ├── bookmark/ # Bookmark related
│ ├── comment/ # Comment related
│ ├── section/ # Section related
│ ├── torrent/ # Torrent related
│ └── user/ # User related
├── api_client/ # API client implementation
├── config/ # Configuration management
├── utils/ # Utility functions
├── tests/ # Test code
├── doc/ # API documentation
├── pyproject.toml # PEP 517/518 build configuration
├── setup.cfg # Package metadata and configuration
└── requirements.txt # Project dependencies
Features
1. Bookmark Management
- Add bookmark
- Delete bookmark
2. Comment Management
- Get comment list
3. Section Management
- Get section information
4. Torrent Management
- Get torrent list
- Get torrent detail
- Upload torrent
5. User Management
- Get user profile
Installation
Install from PyPI (Recommended)
pip install nexusphp-api
Install from Source
git clone https://github.com/nexusphp/nexusphp-api.git
cd nexusphp-api
pip install -e .
Install Development Dependencies
pip install -r requirements.txt
Quick Start
Basic Usage
from nexusphp_api import NexusAPIClient
# Initialize client
client = NexusAPIClient(
base_url="https://dev.nexusphp.org",
token="your-api-token"
)
# Get current user profile
profile = client.profile.get_profile()
print(f"User: {profile.data.data.username}")
# Add bookmark
bookmark = client.bookmark.add_bookmark(torrent_id=123)
print(f"Bookmark status: {bookmark.msg}")
# Delete bookmark
result = client.bookmark.delete_bookmark(torrent_id=123)
print(f"Delete result: {result.msg}")
Dynamic Configuration Update
# Update token
client.set_token("new-token")
# Update base_url
client.set_base_url("https://api.example.com")
Configuration
The project supports configuration via environment variables:
| Environment Variable | Default Value | Description |
|---|---|---|
| API_BASE_URL | https://api.nexusphp.org | API base URL |
| API_TIMEOUT | 30 | API request timeout (seconds) |
| API_TOKEN | "" | Authentication token |
| LOG_LEVEL | INFO | Log level |
| LOG_FILE | api.log | Log file |
| MAX_RETRIES | 3 | Maximum retry count |
| RETRY_INTERVAL | 1.0 | Retry interval (seconds) |
API Reference
NexusAPIClient Main Class
from nexusphp_api import NexusAPIClient
# Initialize
client = NexusAPIClient(
base_url="https://dev.nexusphp.org", # Optional, default value
token="your-token" # Optional
)
# Sub-clients
client.profile # User profile
client.bookmark # Bookmark management
client.comment # Comment management
client.section # Section management
client.torrent # Torrent management
Available Client Methods
ProfileClient (User Profile)
get_profile(user_id=None, includes=None, include_fields=None)
BookmarkClient (Bookmark)
add_bookmark(torrent_id)delete_bookmark(torrent_id)
CommentClient (Comment)
- See code and documentation
SectionClient (Section)
- See code and documentation
TorrentClient (Torrent)
- See code and documentation
Running Tests
Run All Tests
pytest tests/
Run Specific Tests
pytest tests/test_api_client.py
Run Tests with Coverage
pytest tests/ --cov=nexusphp_api --cov-report=html
Run with unittest
python -m unittest discover tests
Code Quality
The project is configured with the following code quality tools:
Format Code
black .
isort .
Lint Code
flake8 .
Type Check
mypy .
Response Format
All API responses follow this format:
{
"ret": 0, // Result code, 0 means success, other means failure
"msg": "success", // Text message
"data": {}, // Response data
"rid": "uuid", // Request ID
"time": 0.123 // Response time (seconds)
}
Utility Functions
The project provides the following utility functions for data conversion and processing:
from_str- String conversionfrom_int- Integer conversionfrom_int_optional- Optional integer conversionfrom_float- Float conversionfrom_bool- Boolean conversionfrom_none- None conversionfrom_union- Union type conversionfrom_list- List conversionfrom_dict- Dict conversionto_float- Float output conversionto_class- Class instance conversionto_enum- Enum conversion
Development and Contribution
Local Development
- Fork the project repository
- Clone to local
- Install development dependencies
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
Build and Release
# Build package
python -m build
# Release to PyPI
twine upload dist/*
Notes
- Make sure you have a valid API token before use
- Respect API rate limits
- Check the
retfield when processing API responses to confirm success - Network requests will automatically retry (default 3 times)
License
MIT License
Support and Contact
For issues or suggestions, please:
- Submit an Issue: GitHub Issues
- View documentation: Project Wiki
Project details
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 nexusphp_api-0.1.3.tar.gz.
File metadata
- Download URL: nexusphp_api-0.1.3.tar.gz
- Upload date:
- Size: 42.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb598c634955bb308c0ef2dc7998f9983627ac079551d7a2d7873ca159986fd7
|
|
| MD5 |
bad74b58e0b38ac60c696ea381b2a1f8
|
|
| BLAKE2b-256 |
4742336926fabdd93a9a00214a2bcafc027c4648543775d306331f4d5fb1f982
|
File details
Details for the file nexusphp_api-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nexusphp_api-0.1.3-py3-none-any.whl
- Upload date:
- Size: 54.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87b670425436451bfcf94de64add869364e8b1b88851c98fc28ba9f59d83f617
|
|
| MD5 |
a07e04607d97572416fccd137d9f0ebc
|
|
| BLAKE2b-256 |
f19b1d62598baa2556dc00e73c5e4dbe6c8d065034eff57ad8c1a709a97bd966
|