{"id":29196953,"url":"https://github.com/beam-community/avro_ex","last_synced_at":"2026-03-13T14:31:55.871Z","repository":{"id":38272567,"uuid":"103582507","full_name":"beam-community/avro_ex","owner":"beam-community","description":"An Avro Library that emphasizes testability and ease of use.","archived":false,"fork":false,"pushed_at":"2026-01-08T13:06:29.000Z","size":220,"stargazers_count":70,"open_issues_count":11,"forks_count":27,"subscribers_count":11,"default_branch":"main","last_synced_at":"2026-01-24T06:57:04.047Z","etag":null,"topics":["avro","avro-kafka","avro-schema","decoding","encoding","kafka","schema"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/avro_ex/AvroEx.html","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beam-community.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-09-14T21:16:22.000Z","updated_at":"2025-11-14T15:49:35.000Z","dependencies_parsed_at":"2024-03-14T12:28:22.100Z","dependency_job_id":"8b7a7d64-7abf-45e2-b5cb-ead1f2237715","html_url":"https://github.com/beam-community/avro_ex","commit_stats":{"total_commits":108,"total_committers":16,"mean_commits":6.75,"dds":0.4629629629629629,"last_synced_commit":"776676f36b8ee43f27579b8d24ec9a105666cd9e"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/beam-community/avro_ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beam-community%2Favro_ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beam-community%2Favro_ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beam-community%2Favro_ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beam-community%2Favro_ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beam-community","download_url":"https://codeload.github.com/beam-community/avro_ex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beam-community%2Favro_ex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30468293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["avro","avro-kafka","avro-schema","decoding","encoding","kafka","schema"],"created_at":"2025-07-02T06:39:44.931Z","updated_at":"2026-03-13T14:31:55.829Z","avatar_url":"https://github.com/beam-community.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AvroEx\n\nAn [Avro](https://avro.apache.org/) encoding/decoding library written in pure Elixir.\n\n## Documentation\n\nThe docs can be found on [hex.pm](https://hexdocs.pm/avro_ex/AvroEx.html)\n\n## Installation\n\n```elixir\ndef deps do\n  [{:avro_ex, \"~\u003e 2.0\"}]\nend\n```\n\n## Usage\n\n### Schema Decoding\n\nAvro uses schemas to define the shape and contract for data. The schemas that your \napplication uses may be defined locally, or may come from a [Schema Registry](https://docs.confluent.io/platform/current/schema-registry/index.html).\n\nIn either case, the first step is to decode a schema defined as JSON or Elixir terms into a `t:AvroEx.Schema.t/0`\n\n```elixir\niex\u003e AvroEx.decode_schema!([\"int\", \"string\"])\n%AvroEx.Schema{\n  context: %AvroEx.Schema.Context{names: %{}},\n  schema: %AvroEx.Schema.Union{\n    possibilities: [\n      %AvroEx.Schema.Primitive{metadata: %{}, type: :int},\n      %AvroEx.Schema.Primitive{metadata: %{}, type: :string}\n    ]\n  }\n}\n```\n\n`AvroEx` will automatically detect Elixir terms or JSON, so you can decode JSON schemas directly\n\n``` elixir\niex\u003e AvroEx.decode_schema!(\"[\\\"int\\\",\\\"string\\\"]\")\n%AvroEx.Schema{\n  context: %AvroEx.Schema.Context{names: %{}},\n  schema: %AvroEx.Schema.Union{\n    possibilities: [\n      %AvroEx.Schema.Primitive{metadata: %{}, type: :int},\n      %AvroEx.Schema.Primitive{metadata: %{}, type: :string}\n    ]\n  }\n}\n```\n\n#### Strict Schema Decoding\n\nWhen writing an Avro schema, it is helpful to get feedback on unrecognized fields. For this purpose,\nit is recommended to use the `:strict` option to provide additional checks. Note that it is not\nrecommended to use this option in production when pulling externally defined schemas, as they may\nhave published a schema with looser validations.\n\n``` elixir\niex\u003e AvroEx.decode_schema!(%{\"type\" =\u003e \"map\", \"values\" =\u003e \"int\", \"bogus\" =\u003e \"value\"}, strict: true)\n** (AvroEx.Schema.DecodeError) Unrecognized schema key `bogus` for AvroEx.Schema.Map in %{\"bogus\" =\u003e \"value\", \"type\" =\u003e \"map\", \"values\" =\u003e \"int\"}\n    (avro_ex 1.2.0) lib/avro_ex/schema/parser.ex:43: AvroEx.Schema.Parser.parse!/2\n```\n\n\n## Encoding\n\nWhen publishing Avro data, it first must be encoded using the schema.\n\n```elixir\niex\u003e schema = AvroEx.decode_schema!(%{\n                \"type\" =\u003e \"record\",\n                \"name\" =\u003e \"MyRecord\",\n                \"fields\" =\u003e [\n                  %{\"name\" =\u003e \"a\", \"type\" =\u003e \"int\"},\n                  %{\"name\" =\u003e \"b\", \"type\" =\u003e \"string\"},\n                ]\n              })\niex\u003e AvroEx.encode!(schema, %{a: 1, b: \"two\"})\n\u003c\u003c2, 6, 116, 119, 111\u003e\n```\n\n## Decoding\n\nWhen receiving Avro data, decode it using the schema\n\n``` elixir\niex\u003e AvroEx.decode!(schema, \u003c\u003c2, 6, 116, 119, 111\u003e\u003e)\n%{\"a\" =\u003e 1, \"b\" =\u003e \"two\"}\n```\n\n## Schema Encoding\n\n`AvroEx` also supports encoding schemas back to JSON. This may be needed when registering schemas or\nserializing them to disk.\n\n``` elixir\niex\u003e AvroEx.encode_schema(schema)\n\"{\\\"fields\\\":[{\\\"name\\\":\\\"a\\\",\\\"type\\\":{\\\"type\\\":\\\"int\\\"}},{\\\"name\\\":\\\"b\\\",\\\"type\\\":{\\\"type\\\":\\\"string\\\"}}],\\\"name\\\":\\\"MyRecord\\\",\\\"type\\\":\\\"record\\\"}\"\n```\n\nAdditionally, schemas can be encoded to [Parsing Canonical Form](https://avro.apache.org/docs/current/spec.html#Parsing+Canonical+Form+for+Schemas) using\nthe `:canonical` option.\n\n``` elixir\niex\u003e AvroEx.encode_schema(schema, canonical: true)\n\"{\\\"name\\\":\\\"MyRecord\\\",\\\"type\\\":\\\"record\\\",\\\"fields\\\":[{\\\"name\\\":\\\"a\\\",\\\"type\\\":\\\"int\\\"},{\\\"name\\\":\\\"b\\\",\\\"type\\\":\\\"string\\\"}]}\"\n```\n\n### Testing\n\nFor testing convenience, `AvroEx.encodable?/2` is exported to check if data can be\nencoded against the given schema. Note that in production scenarios, it is not\nrecommended to use this function.\n\n```elixir\ndefmodule MyModule.Test do\n  use ExUnit.Case\n\n  setup do\n    data = ...\n    schema = ...\n    {:ok, %{data: data, schema: schema}}\n  end\n\n  describe \"my_function/1\" do\n    test \"builds a structure that can be encoded with our avro schema\", context do\n      result = MyModule.my_function(context.data)\n\n      assert AvroEx.encodable?(context.schema, result)\n    end\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeam-community%2Favro_ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeam-community%2Favro_ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeam-community%2Favro_ex/lists"}