Skip to main content

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.

PyPI Version Python Versions License

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 conversion
  • from_int - Integer conversion
  • from_int_optional - Optional integer conversion
  • from_float - Float conversion
  • from_bool - Boolean conversion
  • from_none - None conversion
  • from_union - Union type conversion
  • from_list - List conversion
  • from_dict - Dict conversion
  • to_float - Float output conversion
  • to_class - Class instance conversion
  • to_enum - Enum conversion

Development and Contribution

Local Development

  1. Fork the project repository
  2. Clone to local
  3. Install development dependencies
  4. Create feature branch
  5. Commit changes
  6. Push to branch
  7. Create Pull Request

Build and Release

# Build package
python -m build

# Release to PyPI
twine upload dist/*

Notes

  1. Make sure you have a valid API token before use
  2. Respect API rate limits
  3. Check the ret field when processing API responses to confirm success
  4. Network requests will automatically retry (default 3 times)

License

MIT License

Support and Contact

For issues or suggestions, please:

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

nexusphp_api-0.1.3.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexusphp_api-0.1.3-py3-none-any.whl (54.5 kB view details)

Uploaded Python 3

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

Hashes for nexusphp_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fb598c634955bb308c0ef2dc7998f9983627ac079551d7a2d7873ca159986fd7
MD5 bad74b58e0b38ac60c696ea381b2a1f8
BLAKE2b-256 4742336926fabdd93a9a00214a2bcafc027c4648543775d306331f4d5fb1f982

See more details on using hashes here.

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

Hashes for nexusphp_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 87b670425436451bfcf94de64add869364e8b1b88851c98fc28ba9f59d83f617
MD5 a07e04607d97572416fccd137d9f0ebc
BLAKE2b-256 f19b1d62598baa2556dc00e73c5e4dbe6c8d065034eff57ad8c1a709a97bd966

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page