Skip to main content

Pdef compiler

Project description

Pdef - Interface definition language for the web
Pdef (pi:def, stands for "protocol definition [language]") is a statically typed interface
definition language which supports JSON and a simple HTTP RPC. It allows to write
interfaces and data structures once and then to generate code and RPC clients/servers for
different languages. It is suitable for public APIs, internal service-oriented APIs,
configuration files, as a format for persistence, cache, message queues, logs, etc.

- Packages, modules, imports and namespaces.
- Circular module imports and type references (with some limitations).
- Simple type system built on a clear separation between data structures and interfaces.
- Message and interface inheritance.
- Chained method invocations.
- Default JSON format and HTTP RPC.
- Pluggable loosely-coupled formats and RPCs.
- Pluggable code generators.

- [Java](
- [Python](
- [Objective-C](

- **[Language guide](docs/**
- [Style guide](docs/
- [JSON format](docs/
- [HTTP RPC](docs/
- [Grammar in BNF](docs/grammar.bnf)
- [Generated and language specific code](docs/
- [How to write a code generator](
- [Google group]( (

- The compiler requires Python 2.7 or Python 3.3.
- Bindings requirements are language specific.

Pdef consists of a compiler, pluggable code generators, and language-specific bindings.

Install the compiler as a python package:
$ pip install pdef-compiler

Or [download]( the archive, unzip it and run:
$ python install

Install the code generators:
$ pip install pdef-java
$ pip install pdef-python
$ pip install pdef-objc

Run the check command with test package to check that the compiler works:
$ pdefc check

Getting Started
Create a package file `myproject.yaml`
name: myproject
- posts
- photos

Create the module files:

namespace myproject;

interface Posts {
get(id int64) Post;

create(title string, text string) Post;

message Post {
id int64;
title string;
text string;
photos list<Photo>;

namespace myproject;

message Photo {
id int64;
url string;

Generate the source code:
$ pdefc generate-java myproject.yaml --out generated/
$ pdefc generate-objc myproject.yaml --out generated/
$ pdefc generate-python myproject.yaml --out generated/

Example package [sources](

namespace world;
from world import continents, space; // Import two modules from a package.

* The world interface.
* A god-like person can use it to rule the world.
interface World {
/** Returns the humans interface. */
humans() Humans; // Returns another interface.

/** Returns the continents interface. */
continents() Continents; // Returns an interface from another module.

/** Switches the light. */
switchDayNight() void;

/** Returns the last world events, the events are polymorphic. */
events(limit int32, offset int64) list<Event>;

interface Humans {
/** Finds a human by id. */
find(id int64) Human;

/** Lists all people. */
all(limit int32, offset int32) list<Human>;

/** Creates a human. */
@post // A post method (a mutator).
create(human Human) Human;

enum Sex {

// An discriminator.
enum EventType {

message Thing { // A simple message definition.
id int64; // an id field of the int64 type.
location Location;

/** Human is a primate of the family Hominidae, and the only extant species of the genus Homo. */
message Human : Thing { // A message with a base message and a docstring.
name string;
birthday datetime;
sex Sex;
continent Continent;

Polymorphic inheritance:
// A polymorphic message with EventType as its discriminator.
message Event {
type EventType @discriminator;
id int32;
time datetime;

// A polymorphic subtype.
message HumanEvent : Event(EventType.HUMAN_EVENT) {
human Human;

// Multi-level polymorphic messages.
message HumanCreated : HumanEvent(EventType.HUMAN_CREATED) {}
message HumanDied : HumanEvent(EventType.HUMAN_DIED) {}

### Curl
Pdef uses an [HTTP RPC](docs/ with a [JSON format](docs/
which are easy to use without specially generated clients. These are examples,
there is no real server.

Create a new human:
$ curl -d human="{\"id\": 1, \"name\":\"John\"}"
"data": {
"id": 1,
"name": "John"

Switch the light:
$ curl -X POST
"data": null

List people:
$ curl ""
"data": [
{"id": 11, "name": "John"},
{"id": 12, "name": "Jane"}

License and Copyright
Copyright: 2013 Ivan Korobkov <>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

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

pdef-compiler-1.2.2.tar.gz (28.9 kB view hashes)

Uploaded source

Supported by

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