SchemaMaximal
d42 schemas ⇆ JSON Schema
Installation
pip3 install schemax
Usage
Translation
>>> import schemax
>>> from d42 import schema
>>> ExampleSchema = schema.str.len(1, 10)
>>> schemax.to_json_schema(ExampleSchema)
{'type': 'string', 'minLength': 1, 'maxLength': 10}
Also, you could use schemax to translate from JSON-Schema to d42 and generate tests interfaces (in future releases) via command line:
schemax translate schema.json
Translation from JSON-Schema to d42-schema for schema.json:
schema.dict({
'number': schema.int.min(1),
optional('street_name'): schema.str,
...: ...
})
schema.json:
{
"type": "object",
"properties": {
"number": { "type": "integer", "minimum": 1 },
"street_name": { "type": "string" }
},
"required": ["number"],
"additionalProperties": true
}
Generation
schemax generate my-schema.yml
This command will generate request and response schemas files, API interface and basic scenarios.
You could add basic url to your API as following: --base-url="http://api.example.com".
Making your schemas and interfaces more "friendly" could --humanize flag.
Using SchemaData object in code
import yaml
from schemax import collect_schema_data, SchemaData
from typing import List
# Also could be JSON OpenAPI file
with open('my_openapi.yaml') as schema_file:
raw_schema = yaml.load(schema_file, yaml.FullLoader)
parsed_data: List[SchemaData] = collect_schema_data(raw_schema)
for item in parsed_data:
print(item.path)
print(item.response_schema_d42)
...
All the data is stored in SchemaData object, which has the following fields:
- http_method: HTTP method of the request.
- path: URL path of the request.
- converted_path: URL path converted to the camel-case for usage in schemax generation.
- args: Arguments of the request.
- queries: Query parameters of the request. Currently unsupported and always '[]'.
- interface_method: Interface name for usage in schemax generation.
- interface_method_humanized: Interface 'humanized' name for usage in schemax generation.
- status: Status code for specified schemas.
- schema_prefix: Schema prefix name for usage in schemax generation.
- schema_prefix_humanized: Schema prefix 'humanized' name for user in schemax generation.
- response_schema: Normalized response schema (without $ref).
- response_schema_d42: Converted to d42 response_schema.
- request_schema: Normalized request schema (without $ref).
- request_schema_d42: Converted to d42 request_schema.
- tags: Tags of the request from OpenAPI schema.
Supported d42 -> JSON Schema types and features
(✅ - done; 🔧 - planned support; ❌ - unsupportable)
- None:
- Bool:
- Int:
- Float:
- Str:
- List:
- Dict:
- Any:
- Date:
- Datetime:
- UUID:
- Type Alias:
- ✅ schema.alias(name, schema) (unwraps to inner schema)
- ❌ schema.bytes
Supported JSON Schema -> d42 types and features
(✅ - done; 🔧 - planned support; ❌ - unsupportable)
- ✅ null
- ✅ boolean
- ✅ integer
- ✅ minimum
- ✅ maximum
- ✅ exclusiveMinimum Keep in mind, that we're just taking exclusiveMinimum + 1 as schema.int.min
- ✅ exclusiveMaximum Keep in mind, that we're just taking exclusiveMaximum - 1 as schema.int.max
- ❌ multiples
- ✅ number
- ✅ minimum
- ✅ maximum
- 🔧 exclusiveMinimum
- 🔧 exclusiveMaximum
- ❌ multiples
- ✅ string
- ✅ array
- ✅ items
- ✅ length
- ✅ prefixItems
- ✅ unevaluatedItems
- ❌ uniqueness
- ✅ object
Metadata
Release files for schemax 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| schemax-2.3.0.tar.gz | 121.1 kB | Without provenance | Details for schemax-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| schemax-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for schemax-2.3.0-py3-none-any.whl |
Total release size: 147.9 kB
Release files / schemax-2.3.0.tar.gz
| Download URL | schemax-2.3.0.tar.gz |
|---|---|
| Size | 121.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
da261c90938b9345c78057c771dc15b7440fb920eafd8d874b8f9132457e1f5f
|
|
BLAKE2b-256 checksum How to use checksums |
f360008ff405ebd47f13181fe4bf30b31433eedec077ad14d2cfd517870900d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / schemax-2.3.0-py3-none-any.whl
| Download URL | schemax-2.3.0-py3-none-any.whl |
|---|---|
| Size | 26.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
673d86e02ff3d26f226f36dedae5c683e8c441dbf7613b619249620b562ed426
|
|
BLAKE2b-256 checksum How to use checksums |
8cafb5960255f8e740c967dd65ab84f5beca0134f3baf3207a826bc36053b62b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for schemax 2.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.