Metadata-Version: 2.4
Name: near-fastapi
Version: 0.1.0
Summary: FastAPI service for NEAR Protocol RPC, account data, and contract view calls
Project-URL: Homepage, https://github.com/mastrophot/near-fastapi
Project-URL: Repository, https://github.com/mastrophot/near-fastapi
Project-URL: Issues, https://github.com/mastrophot/near-fastapi/issues
Author-email: Mastrophot <butrikmax@gmail.com>
License: MIT
License-File: LICENSE
Keywords: api,blockchain,fastapi,near,python
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: fastapi>=0.115.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: pydantic-settings>=2.4.0
Requires-Dist: pydantic>=2.7.0
Requires-Dist: uvicorn>=0.30.0
Provides-Extra: dev
Requires-Dist: build>=1.2.2; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Requires-Dist: respx>=0.21.1; extra == 'dev'
Description-Content-Type: text/markdown

# near-fastapi

Production-ready FastAPI service for NEAR Protocol.

This package exposes a clean REST API for common NEAR operations:

- Network status (mainnet/testnet)
- Account details and access keys
- Contract code hash
- Contract view function calls with JSON decoding

## Install

```bash
pip install near-fastapi
```

## Run

```bash
near-fastapi --host 0.0.0.0 --port 8080
```

Open docs:

- Swagger UI: `http://localhost:8080/docs`
- ReDoc: `http://localhost:8080/redoc`

## API Endpoints

- `GET /health`
- `GET /v1/networks`
- `GET /v1/status?network=mainnet`
- `GET /v1/accounts/{account_id}?network=mainnet`
- `GET /v1/accounts/{account_id}/keys?network=mainnet`
- `GET /v1/contracts/{account_id}/code-hash?network=mainnet`
- `POST /v1/contracts/{account_id}/view`

## Contract View Example

```bash
curl -X POST http://localhost:8080/v1/contracts/social.near/view \
  -H 'Content-Type: application/json' \
  -d '{
    "method": "get",
    "args": {"keys": ["near.social/root"]},
    "network": "mainnet"
  }'
```

## Python Integration Example

```python
from fastapi import FastAPI
from near_fastapi.app import create_app

app: FastAPI = create_app()
```

## NEAR Integration Notes

- Uses official NEAR RPC endpoints:
  - `https://rpc.mainnet.near.org`
  - `https://rpc.testnet.near.org`
- Returns RPC errors as clear HTTP errors.
- Validates account IDs to reduce bad requests early.

## Development

```bash
python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
pytest -q
```

## License

MIT
