{"modulePath":"github.com/voutilad/rp-connect-python","version":"v1.7.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package python\n\n## Constants\n\n```go\nconst SerializerMetaKey = \"_python_serializer\"\n```\n\n## Functions\n\n```go\nfunc DropGlobalReferences(objs []py.PyObjectPtr, ctx context.Context) error\n```\nDropGlobalReferences to a list of PyObjectPtr.\n\n```go\nfunc Evaluate(fn func() error, c chan error, ctx context.Context) error\n```\nEvaluate a given function fn in the context of the main interpreter. A response is provided via the channel c.\n\nXXX This may look a little odd, both returning an error and using a channel, but it's to avoid having to allocate a channel for each call as this function will be called frequently.\n\n```go\nfunc Spawn(legacyMode bool, ctx context.Context) (*subInterpreter, error)\n```\nSpawn a new sub-interpreter.\n\n```go\nfunc StopSub(subInterpreter *subInterpreter, ctx context.Context) error\n```\nStopSub will attempt to shut down a sub-interpreter.\n\n## Types\n\n```go\ntype Callback struct {\n\tName       string\n\tDefinition *py.PyMethodDef\n\tObject     py.PyObjectPtr\n}\n```\n\n```go\nfunc NewCallback(name string, f callbackFunc) (*Callback, error)\n```\n\n```go\ntype ContextAwareMutex struct {\n\t// contains filtered or unexported fields\n}\n```\nA ContextAwareMutex implements a mutex lock that allows for an optional context to be provided so a caller can control if they want a deadline or timeout.\n\n```go\nfunc NewContextAwareMutex() *ContextAwareMutex\n```\n\n```go\nfunc (c *ContextAwareMutex) AssertLocked()\n```\nAssertLocked panics if the ContextAwareMutex is not currently locked by someone.\n\n```go\nfunc (c *ContextAwareMutex) Lock() error\n```\nLock the mutex using a background context.\n\n```go\nfunc (c *ContextAwareMutex) LockWithContext(ctx context.Context) error\n```\nLockWithContext will attempt to take the lock but uses the provided [context.Context](/context#Context) to allow cancellation.\n\n```go\nfunc (c *ContextAwareMutex) Unlock()\n```\nUnlock the mutex. Panics if the mutex is not currently locked in order to speed up debugging.\n\n```go\ntype InterpreterTicket struct {\n\t// contains filtered or unexported fields\n}\n```\nAn InterpreterTicket represents ownership of the interpreter of a particular Runtime. Other than its id, it's opaque to the user.\n\n```go\nfunc (i *InterpreterTicket) Id() int64\n```\nId provides a unique (to the backing Runtime) identifier for an interpreter. The caller may use this for identifying if they're re-using an interpreter.\n\n```go\ntype Mode string\n```\n\n```go\nconst (\n\tIsolated       Mode = \"isolated\"\n\tGlobal         Mode = \"global\"\n\tIsolatedLegacy Mode = \"isolated_legacy\"\n\tInvalidMode    Mode = \"invalid\"\n)\n```\n\n```go\nfunc StringAsMode(s string) Mode\n```\n\n```go\ntype MultiInterpreterRuntime struct {\n\t// contains filtered or unexported fields\n}\n```\nMultiInterpreterRuntime creates and manages multiple Python sub-interpreters.\n\n```go\nfunc NewMultiInterpreterRuntime(exe string, cnt int, legacyMode bool, logger *service.Logger) (*MultiInterpreterRuntime, error)\n```\n\n```go\nfunc (r *MultiInterpreterRuntime) Acquire(ctx context.Context) (*InterpreterTicket, error)\n```\n\n```go\nfunc (r *MultiInterpreterRuntime) Apply(ticket *InterpreterTicket, _ context.Context, f func() error) error\n```\n\n```go\nfunc (r *MultiInterpreterRuntime) Map(ctx context.Context, f func(t *InterpreterTicket) error) error\n```\nMap a function fn over all the interpreters, one at a time. Useful for initializing all interpreters to a given state.\n\n```go\nfunc (r *MultiInterpreterRuntime) Release(ticket *InterpreterTicket) error\n```\n\n```go\nfunc (r *MultiInterpreterRuntime) Start(ctx context.Context) error\n```\nStart the Python runtime. A MultiInterpreterRuntime centralizes modification of the main interpreter in a go routine.\n\n```go\nfunc (r *MultiInterpreterRuntime) Stop(ctx context.Context) error\n```\nStop a running Python Runtime.\n\n```go\ntype Runtime interface {\n\t// Start the Python runtime.\n\tStart(ctx context.Context) error\n\n\t// Stop the Python runtime, removing all interpreter state.\n\tStop(ctx context.Context) error\n\n\t// Acquire ownership of an interpreter until Release is called, providing\n\t// a ticket on success or returning err on error.\n\tAcquire(ctx context.Context) (ticket *InterpreterTicket, err error)\n\n\t// Release ownership of an interpreter identified by the given\n\t// InterpreterTicket.\n\tRelease(token *InterpreterTicket) error\n\n\t// Apply a function f over the interpreter described by the given\n\t// InterpreterTicket.\n\tApply(token *InterpreterTicket, ctx context.Context, f func() error) error\n\n\t// Map a function f over all possible interpreters.\n\t// In the case of multiple interpreters, an error aborts mapping over the\n\t// remainder.\n\tMap(ctx context.Context, f func(ticket *InterpreterTicket) error) error\n}\n```\nA Runtime for a Python interpreter.\n\n```go\ntype Serializer struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewSerializer() (*Serializer, error)\n```\nNewSerializer attempts to compile, import, and prepare a set of Python objects to assist serialization.\n\nThe caller must manage the interpreter state for this to succeed.\n\n```go\nfunc (s *Serializer) DecRef()\n```\n\n```go\nfunc (s *Serializer) JsonBytes(obj py.PyObjectPtr) ([]byte, error)\n```\nJsonBytes serializes the given Python object to JSON, encoded to utf-8 bytes.\n\n```go\nfunc (s *Serializer) JsonString(obj py.PyObjectPtr) (string, error)\n```\nJsonString serializes the given Python object to JSON.\n\n```go\nfunc (s *Serializer) Pickle(obj py.PyObjectPtr) ([]byte, error)\n```\nPickle the given Python object.\n\n```go\ntype SerializerMode string\n```\n\n```go\nconst (\n\t// Pickle SerializerMode will pickle any Python results.\n\tPickle SerializerMode = \"pickle\"\n\n\t// Bloblang SerializerMode will approximate JSON serialization used by Bloblang.\n\tBloblang SerializerMode = \"bloblang\"\n\n\t// None SerializerMode will not attempt serialization and simply pass Python object pointers.\n\tNone SerializerMode = \"none\"\n\n\tInvalidSerializer SerializerMode = \"invalid\"\n)\n```\n\n```go\nfunc StringAsSerializerMode(s string) SerializerMode\n```\n\n```go\ntype SingleInterpreterRuntime struct {\n\t// contains filtered or unexported fields\n}\n```\nSingleInterpreterRuntime provides an implementation for using main Python interpreter.\n\n```go\nfunc NewSingleInterpreterRuntime(exe string, cnt int, logger *service.Logger) (*SingleInterpreterRuntime, error)\n```\n\n```go\nfunc (r *SingleInterpreterRuntime) Acquire(ctx context.Context) (*InterpreterTicket, error)\n```\n\n```go\nfunc (r *SingleInterpreterRuntime) Apply(ticket *InterpreterTicket, ctx context.Context, f func() error) error\n```\n\n```go\nfunc (r *SingleInterpreterRuntime) Map(ctx context.Context, f func(ticket *InterpreterTicket) error) error\n```\n\n```go\nfunc (r *SingleInterpreterRuntime) Release(ticket *InterpreterTicket) error\n```\n\n```go\nfunc (r *SingleInterpreterRuntime) Start(ctx context.Context) error\n```\n\n```go\nfunc (r *SingleInterpreterRuntime) Stop(ctx context.Context) error\n```\n\n","path":"github.com/voutilad/rp-connect-python/internal/impl/python","name":"python","synopsis":"","isRedistributable":true}
