Python API reference
App
The App
class represents a Teo server app.
__init__
Create an app.
Examples
Create an app
main_namespace
Retrieve the main namespace from the app. Namespace is where models, handlers,
decorators and pipeline items are defined. See Namespace
.
Examples
Retrieve the main namespace
setup
Attach some code to run after the database is connected. The parameter Teo
is in generated entities.
Examples
Run custom setup code
program
Define a custom program to run with Teo CLI. The parameter Teo
is in
generated entities.
Examples
Define a custom program
run
Start the Teo server app.
Example
Run an server app
Namespace
Namespace is where things are defined and organized.
is_main
Whether the namespace is the main namespace.
is_std
Whether the namespace is the builtin standard namespace.
path
Get the namespace's path.
Example
Namespace's path
namespace
Get the namespace's child namespace by name
or None
.
namespace_or_create
Get the namespace's child namespace by name
. If not present, create and
return.
namespace_at_path
Get the namespace's child namespace at path.
namespace_or_create_at_path
The the namespace's child namespace at path. If not present, create and return.
define_model_decorator
Define a new model decorator on a namespace.
Example
Define a custom model decorator
define_model_field_decorator
Define a new model field decorator on a namespace.
Example
Define a custom model field decorator
define_model_relation_decorator
Define a new model relation decorator on a namespace.
Example
Define a custom model relation decorator
define_model_property_decorator
Define a new model property decorator on a namespace.
Example
Define a custom model property decorator
define_pipeline_item
Define a custom pipeline item on a namespace.
Example
Define a custom pipeline item
define_transform_pipeline_item
Define a transformer pipeline item. This is a shortcut to
define_pipeline_item
.
Example
Define a custom transformer
Define a custom transformer which errors
define_validator_pipeline_item
Define a validator pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom validator pipeline item with bool return value
Define a custom validator pipeline item with string return value
Define a custom validator pipeline item which errors
define_callback_pipeline_item
Define a callback pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom callback pipeline item
Define a custom callback pipeline item which errors
define_compare_pipeline_item
Define a compare pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom compare pipeline item
define_middleware
Define a middleware on a namespace.
Example
Define a custom middleware
define_handler
Define a custom route handler on a namespace.
Example
Define a custom route handler
define_handler_group
Define a handler group on a namespace.
Example
Define a custom handler group
define_model_handler_group
Define model handlers on a namespace.
Example
Define a custom model handler group
HandlerGroup
A handler group is a container for defining custom route handlers.
define_handler
Define a custom route handler on a handler group.
Example
Define a custom route handler
Request
A request represents an HTTP request.
method
Retrieve the request's method.
path
Retrieve the request's path.
query_string
Retrieve the request's query string.
content_type
Retrieve the request's content type.
headers
Retrieve the request's headers.
ReadOnlyHeaderMap
The ReadOnlyHeaderMap
class represents readonly headers on a request.
keys
Retrieve the header map's keys.
len
Retrieve the length of the header map.
contains_key
Whether the headers contain a specific key.
get
Retrieve the value of a header entry by key
.
Response
The Response
class represents an HTTP response.
empty
Create an empty response.
Example
Create an empty response
string
Create a string response.
Example
Create a simple text response
teon
Create a Teon response.
html
Create an HTML response.
Example
Create an HTML response
data
Create a Teon response which contains a data
field.
data_meta
Create a Teon response which contains a data
field and a meta
field.
file
Create a file response.
Example
Create a file response
redirect
Create a redirect response.
Example
Create a redirect response
set_code
Set the response code.
code
Retrieve the response code.
headers
Retrieve the response headers.
is_empty
Whether the response body is empty.
is_file
Whether the response body is a file.
get_file
Retrieve the response file path. If the response' type is not file, None is returned.
is_text
Whether the response body is text.
get_text
Retrieve the response text. If the response' type is not text, None is returned.
is_teon
Whether the response body is a teon object.
get_teon
Retrieve the response Teon value. If the response' type is not Teon, None is returned.
ReadWriteHeaderMap
The ReadWriteHeaderMap
class represents readwrite headers on a response.
keys
Retrieve the header map's keys.
len
Retrieve the length of the header map.
contains_key
Whether the headers contain a specific key.
get
Retrieve the value of a header entry by key
.
set
Set a new value of a header entry at key
.
Entity model
API documentation for generated model entities.
find_many
Find many objects with params same as findMany
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | ModelFindManyArgs | The finder |
Examples
Find all users
Find users filtered by name
Find users ordered by createdAt
Find users with posts
find_unique
Find a unique object with params same as find_unique
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | ModelFindUniqueArgs | The finder |
Examples
Find a unique user
find_first
Find an object with params same as find_first
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | ModelFindFirstArgs | The finder |
Examples
Find a user
count_objects
Count objects in the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | ModelCountArgs | The finder |
Examples
Count objects
count_fields
Count fields in the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | ModelCountArgs | The finder |
Examples
Count objects
aggregate
Aggregate on the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | &Value | The finder |
Examples
Aggregate on the model
group_by
Group by on the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | &Value | The finder |
Example
Group by on the model
create
Create a new model object.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | ModelCreateInput | The create data |
Examples
Create a new Post
Entity object
is_new
Returns true if object is new.
is_modified
Returns true if object is modified.
set
Set values to an object. The onSet
pipeline is triggered.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | ModelUpdateInput | The set data |
Examples
Set values to a user
update
Update values on an object.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | ModelScalarUpdateInput | The update data |
Examples
Update values on a user
save
Save an object.
Signature
Examples
Save a post
delete
Delete an object.
Signature
Examples
Delete a post
to_teon
Convert the object to a teon result value.