JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 111
  • Score
    100M100P100Q101146F
  • License MIT

Universal TypeScript client for pyRPC

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/client

The 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/client

Usage

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 to window.location.origin in browsers)
  • headers — Static or async HeadersInit

Keywords

rpc, pyrpc, typescript, client, type-safe, api, remote-procedure-call

License

MIT