python.md

August 31, 2023 · View on GitHub

METADATA

PropertyValueNotes
generator namepythonpass this to the generate command after -g
generator stabilitySTABLE
generator typeCLIENT
generator languagePython
generator language version>=3.8
generator default templating enginehandlebars
helpTxtGenerates a Python client library

Features in this generator:
- type hints on endpoints and model creation
- model parameter names use the spec defined keys and cases
- robust composition (oneOf/anyOf/allOf/not) where payload data is stored in one instance only
- endpoint parameter names use the spec defined keys and cases
- inline schemas are supported at any location including composition
- multiple content types supported in request body and response bodies
- run time type checking + json schema validation
- json schema keyword validation may be selectively disabled with SchemaConfiguration
- enums of type string/integer/boolean typed using typing.Literal
- mypy static type checking run on generated sample
- Sending/receiving decimals as strings supported with type:string format: number -> DecimalSchema
- Sending/receiving uuids as strings supported with type:string format: uuid -> UUIDSchema
- quicker load time for python modules (a single endpoint can be imported and used without loading others)
- composed schemas with type constraints supported (type:object + oneOf/anyOf/allOf)
- schemas are not coerced/cast. For example string + date are both stored as string, and there is a date accessor

CONFIG OPTIONS

These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to configuration docs for more details.

OptionDescriptionValuesDefault
generateSourceCodeOnlySpecifies that only a library source code is to be generated.false
hideGenerationTimestampHides the generation timestamp when files are generated.true
librarylibrary template (sub-template) to use: urllib3urllib3
nonCompliantUseDiscriminatorIfCompositionFailsWhen true, If the payload fails to validate against composed schemas (allOf/anyOf/oneOf/not) and a discriminator is present, then ignore the composition validation errors and attempt to use the discriminator to validate the payload.
Note: setting this to true makes the generated client not comply with json schema because it ignores composition validation errors. Please consider making your schemas more restrictive rather than setting this to true. You can do that by:
  • defining the propertyName as an enum with only one value in the schemas that are in your discriminator map
  • setting additionalProperties: false in your schemas
true
If composition fails and a discriminator exists, the composition errors will be ignored and validation will be attempted with the discriminator
false
Composition validation must succeed. Discriminator validation must succeed.
false
packageNamepython package name (convention: snake_case).openapi_client
packageUrlpython package URL.null
packageVersionpython package version.1.0.0
projectNamepython project name in setup.py (e.g. petstore-api).null
recursionLimitSet the recursion limit. If not set, use the system default value.null
templatingEnginetemplate engine
handlebars
handlebars templating engine
handlebars
useNoseuse the nose test frameworkfalse

INSTANTIATION TYPES

Type/AliasInstantiated By
arraytuple
booleanbool
integerint
nullNone
numbertyping.Union[float, int]
objectimmutabledict.immutabledict
stringstr

LANGUAGE PRIMITIVES

  • bool
  • bytes
  • date
  • datetime
  • dict
  • file
  • file_type
  • float
  • int
  • list
  • none_type
  • object
  • str

RESERVED WORDS

  • and
  • as
  • assert
  • async
  • await
  • bool
  • break
  • class
  • continue
  • def
  • del
  • dict
  • elif
  • else
  • except
  • exec
  • false
  • finally
  • float
  • for
  • from
  • global
  • if
  • immutabledict
  • import
  • in
  • int
  • is
  • lambda
  • list
  • none
  • nonlocal
  • not
  • or
  • pass
  • print
  • property
  • raise
  • return
  • self
  • str
  • true
  • try
  • tuple
  • while
  • with
  • yield

FEATURE SET

Client Modification Feature

NameSupportedDefined By
BasePathToolingExtension
AuthorizationsToolingExtension
UserAgentToolingExtension
MockServerToolingExtension

Components Feature

NameSupportedDefined By
schemasOAS3
responsesOAS3
parametersOAS3
examplesOAS3
requestBodiesOAS3
headersOAS3
securitySchemesOAS3
linksOAS3
callbacksOAS3
pathItemsOAS3

Data Type Feature

NameSupportedDefined By
CustomOAS2,OAS3
Int32OAS2,OAS3
Int64OAS2,OAS3
IntegerOAS2,OAS3
FloatOAS2,OAS3
DoubleOAS2,OAS3
NumberOAS2,OAS3
StringOAS2,OAS3
ByteOAS2,OAS3
BinaryOAS2,OAS3
BooleanOAS2,OAS3
DateOAS2,OAS3
DateTimeOAS2,OAS3
PasswordOAS2,OAS3
FileOAS2
UuidOAS2,OAS3
ArrayOAS2,OAS3
NullOAS3
AnyTypeOAS2,OAS3
ObjectOAS2,OAS3
EnumOAS2,OAS3

Documentation Feature

NameSupportedDefined By
ReadmeToolingExtension
ServersOAS3
SecurityOAS2,OAS3
ComponentSchemasOAS3
ComponentResponsesOAS3
ComponentParametersOAS3
ComponentRequestBodiesOAS3
ComponentHeadersOAS3
ComponentSecuritySchemesOAS3
ComponentLinksOAS3
ComponentCallbacksOAS3
ComponentPathItemsOAS3
ApiToolingExtension

Global Feature

NameSupportedDefined By
InfoOAS2,OAS3
ServersOAS3
PathsOAS2,OAS3
WebhooksOAS3
ComponentsOAS3
SecurityOAS2,OAS3
TagsOAS2,OAS3
ExternalDocsOAS2,OAS3

Operation Feature

NameSupportedDefined By
Responses_HttpStatusCodeOAS3
Responses_RangedResponseCodesOAS3
Responses_DefaultOAS3
Responses_RedirectionResponseOAS3

Parameter Feature

NameSupportedDefined By
NameOAS2,OAS3
RequiredOAS2,OAS3
In_PathOAS2,OAS3
In_QueryOAS2,OAS3
In_HeaderOAS2,OAS3
In_CookieOAS3
Style_MatrixOAS3
Style_LabelOAS3
Style_FormOAS3
Style_SimpleOAS3
Style_SpaceDelimitedOAS3
Style_PipeDelimitedOAS3
Style_DeepObjectOAS3
ExplodeOAS3
SchemaOAS3
ContentOAS3

Schema Feature

NameSupportedDefined By
AdditionalPropertiesOAS2,OAS3
AllOfOAS2,OAS3
AnyOfOAS3
ConstOAS3
ContainsOAS3
DefaultOAS2,OAS3
DependentRequiredOAS3
DependentSchemasOAS3
DiscriminatorOAS2,OAS3
EnumOAS2,OAS3
ExclusiveMinimumOAS2,OAS3
ExclusiveMaximumOAS2,OAS3
FormatOAS2,OAS3
ItemsOAS2,OAS3
MaxContainsOAS3
MaxItemsOAS2,OAS3
MaxLengthOAS2,OAS3
MaxPropertiesOAS2,OAS3
MaximumOAS2,OAS3
MinContainsOAS3
MinItemsOAS2,OAS3
MinLengthOAS2,OAS3
MinPropertiesOAS2,OAS3
MinimumOAS2,OAS3
MultipleOfOAS2,OAS3
NotOAS3
NullableOAS3
OneOfOAS3
PatternOAS2,OAS3
PatternPropertiesOAS3
PrefixItemsOAS3
PropertiesOAS2,OAS3
PropertyNamesOAS3
RequiredOAS2,OAS3
TypeOAS2,OAS3
UnevaluatedItemsOAS3
UnevaluatedPropertiesOAS3
UniqueItemsOAS2,OAS3
XmlOAS2,OAS3

Security Feature

NameSupportedDefined By
HTTP_BasicOAS2,OAS3
ApiKeyOAS2,OAS3
OpenIDConnectOAS3
HTTP_BearerOAS2,OAS3
OAuth2_ImplicitOAS2,OAS3
OAuth2_PasswordOAS2,OAS3
OAuth2_ClientCredentialsOAS2,OAS3
OAuth2_AuthorizationCodeOAS2,OAS3

Wire Format Feature

NameSupportedDefined By
JSONOAS2,OAS3
XMLOAS2,OAS3
PROTOBUFToolingExtension
CustomOAS2,OAS3