Reference
datetime_serializer
module-attribute
An iso8601 serializer for datetime objects.
json_serializer
module-attribute
A serializer for JSON.
json_sorted_serializer
module-attribute
A serializer for JSON with sorted keys
temp_file_storage
module-attribute
A temporary file storage backend (best for testing).
Artifact
Bases: Node[OrmArtifact]
, Generic[T]
A wrapper around an ORM artifact record.
Source code in src/artigraph/core/api/artifact.py
ArtifactFilter
Bases: NodeFilter[A]
Filter artifacts that meet the given conditions.
Source code in src/artigraph/core/api/filter.py
DatetimeSerializer
Bases: Serializer
Serializer for datetime.datetime.
Source code in src/artigraph/core/serializer/datetime.py
deserialize
serialize
FileSystemStorage
Bases: Storage
A storage backend that saves artifacts to the filesystem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory |
str | Path
|
The directory to save artifacts to. |
required |
name |
str
|
The name of the storage backend. |
''
|
Source code in src/artigraph/core/storage/file.py
create
async
Create an artifact in the filesystem and return its location
delete
async
exists
async
read
async
Filter
Bases: FrozenDataclass
Base class for where clauses.
Source code in src/artigraph/core/api/filter.py
__and__
__or__
compose
GraphModel
Bases: GraphObject[OrmModelArtifact, OrmBase, NodeFilter[Any]]
A base for all modeled artifacts.
Source code in src/artigraph/core/model/base.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
graph_orm_type
class-attribute
The ORM type for this model.
graph_model_data
graph_model_init
classmethod
Initialize the artifact model, migrating it if necessary.
GraphObject
Bases: ABC
, Generic[S, R, F]
Base for objects that can be converted to and from Artigraph ORM records.
Source code in src/artigraph/core/api/base.py
graph_orm_type
class-attribute
The ORM type that represents this object.
graph_dump_related
abstractmethod
async
graph_dump_self
abstractmethod
async
graph_filter_related
abstractmethod
classmethod
Get the filters for records of related ORM records required to construct this object.
graph_filter_self
abstractmethod
JsonSerializer
Bases: Serializer[Any]
A serializer for JSON.
Source code in src/artigraph/core/serializer/json.py
deserialize
Link
Bases: FrozenDataclass
, GraphObject[L, OrmLink, LinkFilter]
A wrapper around an ORM node link record.
Source code in src/artigraph/core/api/link.py
graph_id
class-attribute
instance-attribute
The unique ID of this link
LinkFilter
Bases: Filter
Filter node links.
Source code in src/artigraph/core/api/filter.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
ancestor
class-attribute
instance-attribute
Links must have one of these nodes as their ancestor.
child
class-attribute
instance-attribute
Links must have one of these nodes as their child.
descendant
class-attribute
instance-attribute
Links must have one of these nodes as their descendant.
id
class-attribute
instance-attribute
Links must have this ID or meet this condition.
Linker
Bases: AnySyncContextManager['Linker']
A context manager for linking graph objects together
Source code in src/artigraph/core/linker.py
link
link(
value: Any,
label: str | None = None,
storage: Storage | None = None,
serializer: Serializer | None = None,
) -> None
Link a graph object to the current node
Source code in src/artigraph/core/linker.py
ModelFilter
Bases: ArtifactFilter[OrmModelArtifact]
, Generic[M]
A filter for models.
Source code in src/artigraph/core/model/filter.py
model_type
class-attribute
instance-attribute
Models must be one of these types.
ModelInfo
dataclass
The info for an artifact model.
Source code in src/artigraph/core/model/base.py
ModelMetadata
Bases: TypedDict
The metadata for an artifact model.
Source code in src/artigraph/core/model/base.py
ModelTypeFilter
Bases: Generic[M]
, Filter
Filter models by their type and version
Source code in src/artigraph/core/model/filter.py
Node
Bases: FrozenDataclass
, GraphObject[N, OrmLink, NodeFilter[Any]]
A wrapper around an ORM node record.
Source code in src/artigraph/core/api/node.py
NodeFilter
Bases: Filter
, Generic[N]
Filter nodes that meet the given conditions
Source code in src/artigraph/core/api/filter.py
ancestor_of
class-attribute
instance-attribute
Nodes must be the ancestor of one of these nodes.
child_of
class-attribute
instance-attribute
Nodes must be the child of one of these nodes.
created_at
class-attribute
instance-attribute
Filter nodes by their creation time.
descendant_of
class-attribute
instance-attribute
Nodes must be the descendant of one of these nodes.
id
class-attribute
instance-attribute
Nodes must have this ID or meet this condition.
label
class-attribute
instance-attribute
Nodes must have a link with one of these labels.
node_type
class-attribute
instance-attribute
Nodes must be one of these types.
parent_of
class-attribute
instance-attribute
Nodes must be the parent of one of these nodes.
NodeTypeFilter
Bases: Filter
, Generic[N]
Filter nodes by their type.
Source code in src/artigraph/core/api/filter.py
not_type
class-attribute
instance-attribute
Nodes must not be one of these types.
subclasses
class-attribute
instance-attribute
Consider subclasses of the given types when filtering.
OrmArtifact
Bases: OrmNode
A base class for artifacts.
Source code in src/artigraph/core/orm/artifact.py
OrmBase
Bases: MappedAsDataclass
, DeclarativeBase
A base class for all database models.
Source code in src/artigraph/core/orm/base.py
OrmDatabaseArtifact
Bases: OrmArtifact
An artifact saved directly in the database.
Source code in src/artigraph/core/orm/artifact.py
OrmLink
Bases: OrmBase
A link between two nodes.
Source code in src/artigraph/core/orm/link.py
id
class-attribute
instance-attribute
The ID of the link.
label
class-attribute
instance-attribute
A label for the link - labels must be unique for a given source node.
source_id
class-attribute
instance-attribute
The ID of the node from which this link originates.
OrmModelArtifact
Bases: OrmDatabaseArtifact
An artifact that is a model.
Source code in src/artigraph/core/orm/artifact.py
model_artifact_type_name
class-attribute
instance-attribute
The type of the model.
OrmNode
Bases: OrmBase
A base class for describing a node in a graph.
Source code in src/artigraph/core/orm/node.py
id
class-attribute
instance-attribute
The unique ID of this node
node_type
class-attribute
instance-attribute
The type of the node link.
polymorphic_identity
class-attribute
The type of the node - should be overridden by subclasses and passed to mapper args.
is_abstract
classmethod
Returns True if the class is abstract. That is, it defines a polymorphic identity.
OrmRemoteArtifact
Bases: OrmArtifact
An artifact saved via a storage backend.
Source code in src/artigraph/core/orm/artifact.py
remote_artifact_location
class-attribute
instance-attribute
A string describing where the artifact is stored.
SaveSpec
dataclass
Information about how to save an artifact.
Source code in src/artigraph/core/api/artifact.py
serializers
class-attribute
instance-attribute
The serializers to try when saving the artifact.
storage
class-attribute
instance-attribute
The storage to use when saving the artifact.
create_artifact
Create an artifact from a value.
Source code in src/artigraph/core/api/artifact.py
Serializer
Bases: ABC
, Generic[T]
A type of artifact that can be serialized to a string or bytes.
Source code in src/artigraph/core/serializer/base.py
name
instance-attribute
A globally unique name for this serializer.
This will typically be of the form "library_name.SerializerName". You should avoid
using dynamic values like __name__
or __qualname__
as these may change between
versions of the library or if you move the class to a different module.
The serializer name will be used to recover this class from a when deserializing artifacts so it must not change between versions of the library. If you need to change the name, you should create and register a subclass with the new name and deprecate the old one.
deserialize
abstractmethod
register
Register a serializer.
It's recommended that each serializer be defined and registerd in a separate module so that users can select which serializers they want to use by importing the module. Thus if a user does not import a serializer if will not be registered. This is important for two reasons:
- It allows users to avoid importing dependencies they don't need.
- Serializers that supprt the same type will override each other - only the last one registered will be used unless the user explicitly selects one.
Source code in src/artigraph/core/serializer/base.py
Storage
Bases: ABC
A storage backend for artifacts.
Source code in src/artigraph/core/storage/base.py
name
instance-attribute
A globally unique name for this storage.
This will typically be of the form "library_name-storage_name". You should avoid
using dynamic values like __name__
or __qualname__
as these may change between
versions of the library or if you move the class to a different module.
The storage name will be used to recover this class when loading data from records. It must not change between versions of the library. If you need to change the name, you should create and register a subclass with the new name and deprecate the old one.
create
abstractmethod
async
delete
abstractmethod
async
exists
abstractmethod
async
read
abstractmethod
async
register
Register a storage backend.
It's recommended that each storage backend be defined and registerd in a separate module so that users can select which storage they want to use by importing the module. Thus, if a user does not import a storage backend it will not be registered. This is important because some storage backends may have dependencies that are not installed.
Source code in src/artigraph/core/storage/base.py
update
abstractmethod
async
ValueFilter
Bases: Filter
, Generic[T]
Filter a column by comparing it to a value.
Source code in src/artigraph/core/api/filter.py
column
class-attribute
instance-attribute
The column to filter.
eq
class-attribute
instance-attribute
The column must be equal to this value.
ge
class-attribute
instance-attribute
The column must be greater than or equal to this value.
gt
class-attribute
instance-attribute
The column must be greater than this value.
ilike
class-attribute
instance-attribute
The column must match this pattern, case-insensitive.
in_
class-attribute
instance-attribute
The column must be one of these values.
is_
class-attribute
instance-attribute
The column must be this value.
is_not
class-attribute
instance-attribute
The column must not be this value.
le
class-attribute
instance-attribute
The column must be less than or equal to this value.
like
class-attribute
instance-attribute
The column must match this pattern.
lt
class-attribute
instance-attribute
The column must be less than this value.
ne
class-attribute
instance-attribute
The column must not be equal to this value.
not_in
class-attribute
instance-attribute
The column must not be one of these values.
against
current_engine
current_engine(
engine: AsyncEngine | str,
*,
create_tables: bool = False
) -> Iterator[AsyncEngine]
Define which engine to use in the context.
Source code in src/artigraph/core/db.py
current_linker
current_session
current_session(
session_maker: async_sessionmaker[AsyncSession]
| None = None,
) -> AsyncContextManager[AsyncSession]
A context manager for an asynchronous database session.
dataclass
A decorator that makes a class into a dataclass GraphModel.
See: dataclass
Source code in src/artigraph/core/model/dataclasses.py
delete
async
Delete records matching the given filter.
Source code in src/artigraph/core/api/funcs.py
delete_many
async
Delete records.
Source code in src/artigraph/core/api/funcs.py
delete_one
async
exists
async
get_polymorphic_identities
get_polymorphic_identities(
node_types: Sequence[type[OrmNode]],
*,
subclasses: bool = False
) -> Sequence[str]
Get the polymorphic identities of the given node types and optionall their subclasses.
Source code in src/artigraph/core/orm/node.py
get_serializer_by_name
Get a serializer by name.
get_serializer_by_type
Get a serializer by type.
Source code in src/artigraph/core/serializer/base.py
linked
linked(
*,
node_type: Callable[[], Node] = Node,
is_method: bool = False,
include: str | Collection[str] = (),
exclude: str | Collection[str] = ()
) -> Callable[[F], F]
Capture the inputs and outputs of a function using Artigraph
Source code in src/artigraph/core/linker.py
load_deserialized_artifact_value
async
Load the value of an artifact from its ORM record.
Source code in src/artigraph/core/api/artifact.py
load_extras
Load extra modules.
This is useful for registering serializers from 3rd party libraries.
Source code in src/artigraph/extras/__init__.py
read
async
Read records that match the given filter.
Source code in src/artigraph/core/api/funcs.py
read_one
async
Read a record that matches the given filter.
Source code in src/artigraph/core/api/funcs.py
read_one_or_none
async
Read a record that matches the given filter or None if no record is found.
Source code in src/artigraph/core/api/funcs.py
set_engine
Set the current engine and whether to try creating tables if they don't exist.
Tables are only created when the engine is retrieved for the first time.
Source code in src/artigraph/core/db.py
write_many
async
S3 storage backend for Artigraph.
S3Storage
Bases: Storage
S3 storage backend for Artigraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket |
str
|
The name of the S3 bucket. |
required |
prefix |
str
|
The prefix to use for all S3 keys. |
''
|
s3_client |
BaseClient
|
The S3 client to use. |
required |
Source code in src/artigraph/extras/aws.py
create
async
Create an S3 object and return is key.
Source code in src/artigraph/extras/aws.py
delete
async
exists
async
Check if an S3 object exists.
Source code in src/artigraph/extras/aws.py
read
async
create_graph
async
Create a NetworkX graph from an Artigraph node.
Source code in src/artigraph/extras/networkx.py
array_serializer
module-attribute
A serializer for numpy arrays.
ArraySerializer
Bases: Serializer[ndarray]
A serializer for numpy arrays.
Source code in src/artigraph/extras/numpy.py
deserialize
staticmethod
Deserialize a numpy array.
Source code in src/artigraph/extras/numpy.py
serialize
staticmethod
Serialize a numpy array.
Source code in src/artigraph/extras/numpy.py
dataframe_serializer
module-attribute
A serializer for Pandas dataframes.
DataFrameSerializer
Bases: Serializer[DataFrame]
A serializer for Pandas dataframes.
Source code in src/artigraph/extras/pandas.py
deserialize
staticmethod
figure_json_serializer
module-attribute
Serialize a plotly figure
FigureJsonSerializer
Bases: Serializer[Figure | FigureWidget]
Serialize a plotly figure
Source code in src/artigraph/extras/plotly.py
figure_from_networkx
Create a figure from a NetworkX graph
Source code in src/artigraph/extras/plotly.py
dataframe_serializer
module-attribute
A serializer for Polars dataframes that uses the parquet file format.
DataFrameSerializer
Bases: Serializer[DataFrame]
A serializer for Polars dataframes.
Source code in src/artigraph/extras/polars.py
deserialize
feather_serializer
module-attribute
A serializer for PyArrow tables using Feather.
parquet_serializer
module-attribute
A serializer for PyArrow tables using Parquet.
ArrowSerializer
Bases: Serializer[Table]
A serializer for PyArrow tables.
Source code in src/artigraph/extras/pyarrow.py
deserialize
deserialize_feather
deserialize_parquet
serialize
Serialize a PyArrow table.
Source code in src/artigraph/extras/pyarrow.py
serialize_feather
serialize_parquet
PydanticModel
Bases: GraphModel
, BaseModel
A base for all artifacts modeled with Pydantic.