add new public api to get the fullname of a schema
MODIFY
fastavro/_schema.pyx
fastavro/_schema.pyx
@@ -33,6 +33,10 @@ cpdef inline str extract_logical_type(schema):
return None
+cpdef fullname(schema):
+ return schema_name(schema, "")[1]
+
+
cpdef schema_name(schema, parent_ns):
try:
name = schema['name']

MODIFY
fastavro/_schema_py.py
fastavro/_schema_py.py
@@ -33,6 +33,37 @@ def extract_logical_type(schema):
return None
+def fullname(schema):
+ """Returns the fullname of a schema
+
+ Parameters
+ ----------
+ schema: dict
+ Input schema
+
+
+ Example::
+
+ from fastavro.schema import fullname
+
+ schema = {
+ 'doc': 'A weather reading.',
+ 'name': 'Weather',
+ 'namespace': 'test',
+ 'type': 'record',
+ 'fields': [
+ {'name': 'station', 'type': 'string'},
+ {'name': 'time', 'type': 'long'},
+ {'name': 'temp', 'type': 'int'},
+ ],
+ }
+
+ fname = fullname(schema)
+ assert fname == "test.Weather"
+ """
+ return schema_name(schema, "")[1]
+
+
def schema_name(schema, parent_ns):
try:
name = schema['name']

MODIFY
fastavro/schema.py
fastavro/schema.py
@@ -13,7 +13,12 @@ extract_logical_type = _schema.extract_logical_type
# Public API
load_schema = _schema.load_schema
parse_schema = _schema.parse_schema
+fullname = _schema.fullname
__all__ = [
- 'UnknownType', 'load_schema', 'SchemaParseException', 'parse_schema',
+ 'UnknownType',
+ 'load_schema',
+ 'SchemaParseException',
+ 'parse_schema',
+ 'fullname',
]

MODIFY
tests/test_schema.py
tests/test_schema.py
import pytest
import fastavro
-from fastavro.schema import SchemaParseException, UnknownType, parse_schema
+from fastavro.schema import (
+ SchemaParseException, UnknownType, parse_schema, fullname
+)
pytestmark = pytest.mark.usefixtures("clean_schemas")
@@ -250,3 +252,14 @@ def test_doc_left_in_parse_schema():
]
}
assert schema == parse_schema(schema, _write_hint=False)
+
+
+def test_schema_fullname_api():
+ schema = {
+ "type": "record",
+ "namespace": "namespace",
+ "name": "test_schema_fullname_api",
+ "fields": [],
+ }
+
+ assert fullname(schema) == "namespace.test_schema_fullname_api"

add new public api to get the fullname of a schema (#397)