Package Exports
- @pyrpc/client
- @pyrpc/client/dist/index.js
- @pyrpc/client/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@pyrpc/client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@pyrpc/client
Universal TypeScript client for pyRPC. Type-safe RPC calls to your Python backend — install, import, call.
Installation
npm install @pyrpc/client
# or
pnpm add @pyrpc/client
# or
bun add @pyrpc/clientThe postinstall script in @pyrpc/types will prompt for your server URL and generate typed contracts automatically.
For CI, set the PYRPC_URL environment variable:
PYRPC_URL=https://api.example.com npm install @pyrpc/clientUsage
import { createClient } from "@pyrpc/client";
import type { Types } from "@pyrpc/types";
const client = createClient<Types>({
baseUrl: "https://api.example.com",
});
const user = await client.get_user(1);
console.log(user.name);The proxy-based API lets you call any remote procedure as a local method. Parameters are passed positionally or as a single object for named arguments.
Error handling
import { createClient, PyRPCError } from "@pyrpc/client";
try {
await client.delete_user(1);
} catch (error) {
if (error instanceof PyRPCError) {
console.error(error.code, error.message);
}
}API
createClient<TTypes>(options?)
Creates a proxy client that forwards method calls to the server.
baseUrl— Server root URL (defaults towindow.location.originin browsers)headers— Static or asyncHeadersInit
Keywords
rpc, pyrpc, typescript, client, type-safe, api, remote-procedure-call
License
MIT