{"id":13478423,"url":"https://github.com/google/tarpc","last_synced_at":"2025-05-13T17:04:14.412Z","repository":{"id":37664709,"uuid":"51486006","full_name":"google/tarpc","owner":"google","description":"An RPC framework for Rust with a focus on ease of use.","archived":false,"fork":false,"pushed_at":"2025-04-25T06:07:37.000Z","size":1472,"stargazers_count":3450,"open_issues_count":49,"forks_count":205,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-05-06T16:17:08.395Z","etag":null,"topics":["asynchronous-programming","futures","rpc-framework","rust","tokio"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-02-11T01:07:24.000Z","updated_at":"2025-05-04T23:44:06.000Z","dependencies_parsed_at":"2024-01-21T21:07:20.389Z","dependency_job_id":"386d2b94-967b-4062-9b93-8ca4e4cf8342","html_url":"https://github.com/google/tarpc","commit_stats":{"total_commits":757,"total_committers":55,"mean_commits":"13.763636363636364","dds":0.3910171730515192,"last_synced_commit":"d91a9f88c9e8377b8ecba241290b81fd5c938a0b"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Ftarpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Ftarpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Ftarpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Ftarpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/tarpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990456,"owners_count":21995773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-programming","futures","rpc-framework","rust","tokio"],"created_at":"2024-07-31T16:01:56.783Z","updated_at":"2025-05-13T17:04:14.374Z","avatar_url":"https://github.com/google.png","language":"Rust","funding_links":[],"categories":["Rust","rust","Service Toolkits"],"sub_categories":["Rust"],"readme":"[![Crates.io][crates-badge]][crates-url]\n[![MIT licensed][mit-badge]][mit-url]\n[![Build status][gh-actions-badge]][gh-actions-url]\n[![Discord chat][discord-badge]][discord-url]\n\n[crates-badge]: https://img.shields.io/crates/v/tarpc.svg\n[crates-url]: https://crates.io/crates/tarpc\n[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[mit-url]: LICENSE\n[gh-actions-badge]: https://github.com/google/tarpc/workflows/Continuous%20Integration/badge.svg\n[gh-actions-url]: https://github.com/google/tarpc/actions?query=workflow%3A%22Continuous+Integration%22\n[discord-badge]: https://img.shields.io/discord/647529123996237854.svg?logo=discord\u0026style=flat-square\n[discord-url]: https://discord.gg/gXwpdSt\n\n# tarpc\n\n\u003c!-- cargo-sync-readme start --\u003e\n\n*Disclaimer*: This is not an official Google product.\n\ntarpc is an RPC framework for rust with a focus on ease of use. Defining a\nservice can be done in just a few lines of code, and most of the boilerplate of\nwriting a server is taken care of for you.\n\n[Documentation](https://docs.rs/crate/tarpc/)\n\n## What is an RPC framework?\n\"RPC\" stands for \"Remote Procedure Call,\" a function call where the work of\nproducing the return value is being done somewhere else. When an rpc function is\ninvoked, behind the scenes the function contacts some other process somewhere\nand asks them to evaluate the function instead. The original function then\nreturns the value produced by the other process.\n\nRPC frameworks are a fundamental building block of most microservices-oriented\narchitectures. Two well-known ones are [gRPC](http://www.grpc.io) and\n[Cap'n Proto](https://capnproto.org/).\n\ntarpc differentiates itself from other RPC frameworks by defining the schema in code,\nrather than in a separate language such as .proto. This means there's no separate compilation\nprocess, and no context switching between different languages.\n\nSome other features of tarpc:\n- Pluggable transport: any type implementing `Stream\u003cItem = Request\u003e + Sink\u003cResponse\u003e` can be\n  used as a transport to connect the client and server.\n- `Send + 'static` optional: if the transport doesn't require it, neither does tarpc!\n- Cascading cancellation: dropping a request will send a cancellation message to the server.\n  The server will cease any unfinished work on the request, subsequently cancelling any of its\n  own requests, repeating for the entire chain of transitive dependencies.\n- Configurable deadlines and deadline propagation: request deadlines default to 10s if\n  unspecified. The server will automatically cease work when the deadline has passed. Any\n  requests sent by the server that use the request context will propagate the request deadline.\n  For example, if a server is handling a request with a 10s deadline, does 2s of work, then\n  sends a request to another server, that server will see an 8s deadline.\n- Distributed tracing: tarpc is instrumented with\n  [tracing](https://github.com/tokio-rs/tracing) primitives extended with\n  [OpenTelemetry](https://opentelemetry.io/) traces. Using a compatible tracing subscriber like\n  [Jaeger](https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-jaeger),\n  each RPC can be traced through the client, server, and other dependencies downstream of the\n  server. Even for applications not connected to a distributed tracing collector, the\n  instrumentation can also be ingested by regular loggers like\n  [env_logger](https://github.com/env-logger-rs/env_logger/).\n- Serde serialization: enabling the `serde1` Cargo feature will make service requests and\n  responses `Serialize + Deserialize`. It's entirely optional, though: in-memory transports can\n  be used, as well, so the price of serialization doesn't have to be paid when it's not needed.\n\n## Usage\nAdd to your `Cargo.toml` dependencies:\n\n```toml\ntarpc = \"0.36\"\n```\n\nThe `tarpc::service` attribute expands to a collection of items that form an rpc service.\nThese generated types make it easy and ergonomic to write servers with less boilerplate.\nSimply implement the generated service trait, and you're off to the races!\n\n## Example\n\nThis example uses [tokio](https://tokio.rs), so add the following dependencies to\nyour `Cargo.toml`:\n\n```toml\nanyhow = \"1.0\"\nfutures = \"0.3\"\ntarpc = { version = \"0.36\", features = [\"tokio1\"] }\ntokio = { version = \"1.0\", features = [\"rt-multi-thread\", \"macros\"] }\n```\n\nIn the following example, we use an in-process channel for communication between\nclient and server. In real code, you will likely communicate over the network.\nFor a more real-world example, see [example-service](example-service).\n\nFirst, let's set up the dependencies and service definition.\n\n```rust\nuse futures::prelude::*;\nuse tarpc::{\n    client, context,\n    server::{self, Channel},\n};\n\n// This is the service definition. It looks a lot like a trait definition.\n// It defines one RPC, hello, which takes one arg, name, and returns a String.\n#[tarpc::service]\ntrait World {\n    /// Returns a greeting for name.\n    async fn hello(name: String) -\u003e String;\n}\n```\n\nThis service definition generates a trait called `World`. Next we need to\nimplement it for our Server struct.\n\n```rust\n// This is the type that implements the generated World trait. It is the business logic\n// and is used to start the server.\n#[derive(Clone)]\nstruct HelloServer;\n\nimpl World for HelloServer {\n    async fn hello(self, _: context::Context, name: String) -\u003e String {\n        format!(\"Hello, {name}!\")\n    }\n}\n```\n\nLastly let's write our `main` that will start the server. While this example uses an\n[in-process channel](transport::channel), tarpc also ships a generic [`serde_transport`]\nbehind the `serde-transport` feature, with additional [TCP](serde_transport::tcp) functionality\navailable behind the `tcp` feature.\n\n```rust\n#[tokio::main]\nasync fn main() -\u003e anyhow::Result\u003c()\u003e {\n    let (client_transport, server_transport) = tarpc::transport::channel::unbounded();\n\n    let server = server::BaseChannel::with_defaults(server_transport);\n    tokio::spawn(\n        server.execute(HelloServer.serve())\n            // Handle all requests concurrently.\n            .for_each(|response| async move {\n                tokio::spawn(response);\n            }));\n\n    // WorldClient is generated by the #[tarpc::service] attribute. It has a constructor `new`\n    // that takes a config and any Transport as input.\n    let mut client = WorldClient::new(client::Config::default(), client_transport).spawn();\n\n    // The client has an RPC method for each RPC defined in the annotated trait. It takes the same\n    // args as defined, with the addition of a Context, which is always the first arg. The Context\n    // specifies a deadline and trace information which can be helpful in debugging requests.\n    let hello = client.hello(context::current(), \"Stim\".to_string()).await?;\n\n    println!(\"{hello}\");\n\n    Ok(())\n}\n```\n\n## Service Documentation\n\nUse `cargo doc` as you normally would to see the documentation created for all\nitems expanded by a `service!` invocation.\n\n\u003c!-- cargo-sync-readme end --\u003e\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Ftarpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Ftarpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Ftarpc/lists"}