schema

Pydantic schema logic

Pydantic schema logic Question: So, I’m building an API to interact with my personal wine labels collections database. For what I understand, a pydantic model purpose is to serve as a "verifier" of the schema that is sent to the API. So, my pydantic schema for adding a label is the following: from pydantic import …

Total answers: 1

consuming Kafka Avro massages in Python

consuming Kafka Avro massages in Python Question: I am trying to consume messages from Kafka Avro in Python. We have it in Java, and it’s working, but when trying to consume it in the Jupyter notebook, Parsing does not work. I followed the example given by the documentation: (I’ve removed conf information for security reasons) …

Total answers: 1

What is the difference between a Marshmallow field defined with `data_key` and one defined with `attribute` (with the identifiers reversed?)

What is the difference between a Marshmallow field defined with `data_key` and one defined with `attribute` (with the identifiers reversed?) Question: Is there a difference between a marshmallow.Schema (v3.0+) where a field with name foo is defined with attribute=”bar”, and another where a field with name bar is defined with data_key=”foo”? Both seem to serialize …

Total answers: 2

How to validate structure (or schema) of dictionary in Python?

How to validate structure (or schema) of dictionary in Python? Question: I have a dictionary with config info: my_conf = { ‘version’: 1, ‘info’: { ‘conf_one’: 2.5, ‘conf_two’: ‘foo’, ‘conf_three’: False, ‘optional_conf’: ‘bar’ } } I want to check if the dictionary follows the structure I need. I’m looking for something like this: conf_structure = …

Total answers: 10

Get list of data types from schema in Apache Spark

Get list of data types from schema in Apache Spark Question: I have the following code in Spark-Python to get the list of names from the schema of a DataFrame, which works fine, but how can I get the list of the data types? columnNames = df.schema.names For example, something like: columnTypes = df.schema.types Is …

Total answers: 3

Is it possible to validate an XML file against XSD 1.1 in Python?

Is it possible to validate an XML file against XSD 1.1 in Python? Question: I want validate an XML file against an XSD file using lxml.XMLSchema. But the problem is the XSD is in 1.1. So it doesn’t work. This is a part of the XML: <?xml version=”1.0″ encoding=”UTF-8″?> <dictionary xsi_noNamespaceSchemaLocation=”!!assert.xsd”> <SizeType>10</SizeType> </dictionary> And this …

Total answers: 2

Execute .sql schema in psycopg2 in Python

Execute .sql schema in psycopg2 in Python Question: I have a PostgreSQL schema stored in .sql file. It looks something like: CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, facebook_id TEXT NOT NULL, name TEXT NOT NULL, access_token TEXT, created INTEGER NOT NULL ); How shall I run this schema after connecting …

Total answers: 2

Dynamically generate import in Python, specifically for a Django model

Dynamically generate import in Python, specifically for a Django model Question: Given a django Model, how could I auto-generate the valid import for it? I have a strictly internal function (only devs will use it) that takes a model and returns some information on it. The problem is, I don’t know how to dynamically import …

Total answers: 4