Apify Unofficial SDK avatar
Apify Unofficial SDK

Under maintenance

Pricing

Pay per usage

Go to Store
Apify Unofficial SDK

Apify Unofficial SDK

Under maintenance

Developed by

cat

cat

Maintained by Community

Apify Unofficial SDK in Other Languanges

0.0 (0)

Pricing

Pay per usage

1

Total users

6

Monthly users

1

Runs succeeded

>99%

Last modified

2 years ago

.actor/Dockerfile

FROM golang:1.20.10-alpine
WORKDIR /app
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
#COPY go.mod go.sum ./
#RUN go mod download && go mod verify
COPY . .
RUN cd src \
&& go mod init example \
&& go mod tidy \
&& go build -o /usr/local/bin/app .
# && go mod edit -replace localhost/apify=../apify \
CMD ["app"]

.actor/actor.json

{
"actorSpecification": 1,
"name": "my-actor-4",
"title": "Empty Python project",
"description": "Empty project in Python.",
"version": "0.0",
"buildTag": "latest",
"meta": {
"templateId": "python-empty"
},
"dockerfile": "./Dockerfile"
}

src/apify/actor.go

package apify
import (
"fmt"
"net/http"
)
////////////////////////////////////////////////////////////
type clientHttp struct {
token string
base_url string
}
func (c * clientHttp) url (path string) string {
return c.base_url + "/" + path
}
func (c * clientHttp) request (method, path string) string {
cli := & http.Client {
//CheckRedirect: redirectPolicyFunc,
}
url := c.url(path)
req, err := http.NewRequest(method, url, nil)
if c.token != "" {
req.Header.Add("Authorization", c.token)
}
res, err := cli.Do(req)
fmt.Println(res, err)
return ""
}
////////////////////////////////////////////////////////////
/**
type storeBase struct {
}
**/
type storeHttp struct {
clientHttp
}
type DatasetStoreHttp struct {
storeHttp
}
type KeyValueStore struct {
storeHttp
}
func (s * KeyValueStore) GetValue (key string) string {
res := s.request("GET", fmt.Sprintf("records/%s", key))
return res
}
////////////////////////////////////////////////////////////
type _actor struct {
kv_store KeyValueStore
}
func newActor() * _actor {
return & _actor {
kv_store: KeyValueStore {
storeHttp {
clientHttp {
token : config.TOKEN,
base_url : fmt.Sprintf("%s/v2/key-value-stores/%s", config.API_PUBLIC_BASE_URL, config.DEFAULT_KEY_VALUE_STORE_ID),
},
},
},
}
}
func (a * _actor) GetInput () string {
return a.GetValue(config.INPUT_KEY)
}
func (a * _actor) GetValue (key string) string {
return a.kv_store.GetValue(key)
}
////////////////////////////////////////////////////////////
// private
var config = newConfiguration()
// public
var Actor = newActor()

src/apify/apify.go

package apify
func Hello() string {
a := TOKEN
println( a )
return "Hello"
}

src/apify/config.go

package apify
import (
"os"
)
type Configuration struct {
ACTOR_BUILD_ID string
ACTOR_BUILD_NUMBER string
ACTOR_EVENTS_WS_URL string
ACTOR_ID string
ACTOR_RUN_ID string
ACTOR_TASK_ID string
API_BASE_URL string
API_PUBLIC_BASE_URL string
CHROME_EXECUTABLE_PATH string
CONTAINER_PORT string
CONTAINER_URL string
DEDICATED_CPUS string
DEFAULT_BROWSER_PATH string
DEFAULT_DATASET_ID string
DEFAULT_KEY_VALUE_STORE_ID string
DEFAULT_REQUEST_QUEUE_ID string
DISABLE_BROWSER_SANDBOX string
HEADLESS string
INPUT_KEY string
INPUT_SECRETS_PRIVATE_KEY_FILE string
INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE string
IS_AT_HOME string
MAX_USED_CPU_RATIO string
MEMORY_MBYTES string
META_ORIGIN string
METAMORPH_AFTER_SLEEP_MILLIS string
PERSIST_STATE_INTERVAL_MILLIS string
PERSIST_STORAGE string
PROXY_HOSTNAME string
PROXY_PASSWORD string
PROXY_PORT string
PROXY_STATUS_URL string
PURGE_ON_START string
STARTED_AT string
TIMEOUT_AT string
TOKEN string
USER_ID string
XVFB string
SYSTEM_INFO_INTERVAL_MILLIS string
}
func _getenv_or(key string, def string) string {
val := os.Getenv(key)
if val == "" { return def }
return val
}
func _getenv(key string) string { return _getenv_or(key, "") }
func newConfiguration() * Configuration {
return & Configuration {
ACTOR_BUILD_ID : _getenv(BUILD_ID),
ACTOR_BUILD_NUMBER : _getenv(BUILD_NUMBER),
ACTOR_EVENTS_WS_URL : _getenv(EVENTS_WEBSOCKET_URL),
ACTOR_ID : _getenv(ID),
ACTOR_RUN_ID : _getenv(RUN_ID),
ACTOR_TASK_ID : _getenv(TASK_ID),
API_BASE_URL : _getenv_or(API_BASE_URL, "https://api.apify.com"),
API_PUBLIC_BASE_URL : _getenv_or(API_PUBLIC_BASE_URL, "https://api.apify.com"),
//CHROME_EXECUTABLE_PATH : _getenv(CHROME_EXECUTABLE_PATH),
//CONTAINER_PORT : container_port or _getenv(WEB_SERVER_PORT, 4321),
//CONTAINER_URL : container_url or _getenv(WEB_SERVER_URL, "http://localhost:4321"),
//DEDICATED_CPUS : _getenv(DEDICATED_CPUS),
//DEFAULT_BROWSER_PATH : _getenv(DEFAULT_BROWSER_PATH),
DEFAULT_DATASET_ID : _getenv_or(DEFAULT_DATASET_ID, "default"),
DEFAULT_KEY_VALUE_STORE_ID : _getenv_or(DEFAULT_KEY_VALUE_STORE_ID, "default"),
DEFAULT_REQUEST_QUEUE_ID : _getenv_or(DEFAULT_REQUEST_QUEUE_ID, "default"),
//DISABLE_BROWSER_SANDBOX : _getenv(DISABLE_BROWSER_SANDBOX, False),
//HEADLESS : _getenv(HEADLESS, True),
INPUT_KEY : _getenv_or(INPUT_KEY, "INPUT"),
//INPUT_SECRETS_PRIVATE_KEY_FILE : _getenv(INPUT_SECRETS_PRIVATE_KEY_FILE),
//INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE : _getenv(INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE),
IS_AT_HOME : _getenv(IS_AT_HOME),
//MAX_USED_CPU_RATIO : max_used_cpu_ratio or _getenv(MAX_USED_CPU_RATIO, 0.95),
//MEMORY_MBYTES : _getenv(MEMORY_MBYTES),
META_ORIGIN : _getenv(META_ORIGIN),
//METAMORPH_AFTER_SLEEP_MILLIS : metamorph_after_sleep_millis or _getenv(METAMORPH_AFTER_SLEEP_MILLIS, 300000) # noqa: E501
//PERSIST_STATE_INTERVAL_MILLIS : persist_state_interval_millis or _getenv(PERSIST_STATE_INTERVAL_MILLIS, 60000) # noqa: E501
//PERSIST_STORAGE : persist_storage or _getenv(PERSIST_STORAGE, True)
//PROXY_HOSTNAME : proxy_hostname or _getenv(PROXY_HOSTNAME, "proxy.apify.com")
//PROXY_PASSWORD : proxy_password or _getenv(PROXY_PASSWORD)
//PROXY_PORT : proxy_port or _getenv(PROXY_PORT, 8000)
//PROXY_STATUS_URL : proxy_status_url or _getenv(PROXY_STATUS_URL, "http://proxy.apify.com")
//PURGE_ON_START : purge_on_start or _getenv(PURGE_ON_START, False)
//STARTED_AT : _getenv(STARTED_AT)
//TIMEOUT_AT : _getenv(TIMEOUT_AT)
TOKEN : _getenv(TOKEN),
USER_ID : _getenv(USER_ID),
//XVFB : _getenv(XVFB, False)
//SYSTEM_INFO_INTERVAL_MILLIS : system_info_interval_millis or _getenv(SYSTEM_INFO_INTERVAL_MILLIS, 60000)
}
}

src/apify/consts.go

package apify
// ActorJobStatus
const (
// """Available statuses for actor jobs (runs or builds)."""
// Actor job initialized but not started yet
READY = "READY"
// Actor job in progress
RUNNING = "RUNNING"
// Actor job finished successfully
SUCCEEDED = "SUCCEEDED"
// Actor job or build failed
FAILED = "FAILED"
// Actor job currently timing out
TIMING_OUT = "TIMING-OUT"
// Actor job timed out
TIMED_OUT = "TIMED-OUT"
// Actor job currently being aborted by user
ABORTING = "ABORTING"
// Actor job aborted by user
ABORTED = "ABORTED"
/*
@property
def _is_terminal(self) -> bool:
"""Whether this actor job status is terminal."""
return self in (ActorJobStatus.SUCCEEDED, ActorJobStatus.FAILED, ActorJobStatus.TIMED_OUT, ActorJobStatus.ABORTED)
*/
)
// ActorSourceType
const (
// """Available source types for actors."""
// Actor source code is comprised of multiple files
SOURCE_FILES = "SOURCE_FILES"
// Actor source code is cloned from a Git repository
GIT_REPO = "GIT_REPO"
// Actor source code is downloaded using a tarball or Zip file
TARBALL = "TARBALL"
// Actor source code is taken from a GitHub Gist
GITHUB_GIST = "GITHUB_GIST"
)
// ActorEventTypes
/*
const (
// """Possible values of actor event type."""
// Info about resource usage of the actor
SYSTEM_INFO = "systemInfo"
// Sent when the actor is about to migrate
MIGRATING = "migrating"
// Sent when the actor should persist its state (every minute or when migrating)
PERSIST_STATE = "persistState"
// Sent when the actor is aborting
ABORTING = "aborting"
)
*/
// ActorEnvVars
const (
// """Possible Apify-specific environment variables prefixed with "ACTOR_"."""
// TODO: document these
BUILD_ID = "ACTOR_BUILD_ID"
BUILD_NUMBER = "ACTOR_BUILD_NUMBER"
DEFAULT_DATASET_ID = "ACTOR_DEFAULT_DATASET_ID"
DEFAULT_KEY_VALUE_STORE_ID = "ACTOR_DEFAULT_KEY_VALUE_STORE_ID"
DEFAULT_REQUEST_QUEUE_ID = "ACTOR_DEFAULT_REQUEST_QUEUE_ID"
EVENTS_WEBSOCKET_URL = "ACTOR_EVENTS_WEBSOCKET_URL"
ID = "ACTOR_ID"
INPUT_KEY = "ACTOR_INPUT_KEY"
MAX_PAID_DATASET_ITEMS = "ACTOR_MAX_PAID_DATASET_ITEMS"
MEMORY_MBYTES = "ACTOR_MEMORY_MBYTES"
RUN_ID = "ACTOR_RUN_ID"
STARTED_AT = "ACTOR_STARTED_AT"
TASK_ID = "ACTOR_TASK_ID"
TIMEOUT_AT = "ACTOR_TIMEOUT_AT"
WEB_SERVER_PORT = "ACTOR_WEB_SERVER_PORT"
WEB_SERVER_URL = "ACTOR_WEB_SERVER_URL"
)
// ApifyEnvVars
const (
// """Possible Apify-specific environment variables prefixed with "APIFY_"."""
// TODO: document these
API_BASE_URL = "APIFY_API_BASE_URL"
API_PUBLIC_BASE_URL = "APIFY_API_PUBLIC_BASE_URL"
CHROME_EXECUTABLE_PATH = "APIFY_CHROME_EXECUTABLE_PATH"
DEDICATED_CPUS = "APIFY_DEDICATED_CPUS"
DEFAULT_BROWSER_PATH = "APIFY_DEFAULT_BROWSER_PATH"
DISABLE_BROWSER_SANDBOX = "APIFY_DISABLE_BROWSER_SANDBOX"
DISABLE_OUTDATED_WARNING = "APIFY_DISABLE_OUTDATED_WARNING"
FACT = "APIFY_FACT"
HEADLESS = "APIFY_HEADLESS"
INPUT_SECRETS_PRIVATE_KEY_FILE = "APIFY_INPUT_SECRETS_PRIVATE_KEY_FILE"
INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE = "APIFY_INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE"
IS_AT_HOME = "APIFY_IS_AT_HOME"
LOCAL_STORAGE_DIR = "APIFY_LOCAL_STORAGE_DIR"
LOG_FORMAT = "APIFY_LOG_FORMAT"
LOG_LEVEL = "APIFY_LOG_LEVEL"
MAX_USED_CPU_RATIO = "APIFY_MAX_USED_CPU_RATIO"
META_ORIGIN = "APIFY_META_ORIGIN"
METAMORPH_AFTER_SLEEP_MILLIS = "APIFY_METAMORPH_AFTER_SLEEP_MILLIS"
PERSIST_STATE_INTERVAL_MILLIS = "APIFY_PERSIST_STATE_INTERVAL_MILLIS"
PERSIST_STORAGE = "APIFY_PERSIST_STORAGE"
PROXY_HOSTNAME = "APIFY_PROXY_HOSTNAME"
PROXY_PASSWORD = "APIFY_PROXY_PASSWORD"
PROXY_PORT = "APIFY_PROXY_PORT"
PROXY_STATUS_URL = "APIFY_PROXY_STATUS_URL"
PURGE_ON_START = "APIFY_PURGE_ON_START"
SDK_LATEST_VERSION = "APIFY_SDK_LATEST_VERSION"
SYSTEM_INFO_INTERVAL_MILLIS = "APIFY_SYSTEM_INFO_INTERVAL_MILLIS"
TOKEN = "APIFY_TOKEN"
USER_ID = "APIFY_USER_ID"
WORKFLOW_KEY = "APIFY_WORKFLOW_KEY"
XVFB = "APIFY_XVFB"
// Replaced by ActorEnvVars, kept for backward compatibility:
/*
ACTOR_BUILD_ID = "APIFY_ACTOR_BUILD_ID"
ACTOR_BUILD_NUMBER = "APIFY_ACTOR_BUILD_NUMBER"
ACTOR_EVENTS_WS_URL = "APIFY_ACTOR_EVENTS_WS_URL"
ACTOR_ID = "APIFY_ACTOR_ID"
ACTOR_RUN_ID = "APIFY_ACTOR_RUN_ID"
ACTOR_TASK_ID = "APIFY_ACTOR_TASK_ID"
CONTAINER_PORT = "APIFY_CONTAINER_PORT"
CONTAINER_URL = "APIFY_CONTAINER_URL"
DEFAULT_DATASET_ID = "APIFY_DEFAULT_DATASET_ID"
DEFAULT_KEY_VALUE_STORE_ID = "APIFY_DEFAULT_KEY_VALUE_STORE_ID"
DEFAULT_REQUEST_QUEUE_ID = "APIFY_DEFAULT_REQUEST_QUEUE_ID"
INPUT_KEY = "APIFY_INPUT_KEY"
MEMORY_MBYTES = "APIFY_MEMORY_MBYTES"
STARTED_AT = "APIFY_STARTED_AT"
TIMEOUT_AT = "APIFY_TIMEOUT_AT"
// Deprecated, kept for backward compatibility:
ACT_ID = "APIFY_ACT_ID"
ACT_RUN_ID = "APIFY_ACT_RUN_ID"
*/
)
// ActorExitCodes
const (
// """Usual actor exit codes."""
// The actor finished successfully
SUCCESS = 0
// The main function of the actor threw an Exception
ERROR_USER_FUNCTION_THREW = 91
)
// WebhookEventType
const (
// """Events that can trigger a webhook."""
// The actor run was created
ACTOR_RUN_CREATED = "ACTOR.RUN.CREATED"
// The actor run has succeeded
ACTOR_RUN_SUCCEEDED = "ACTOR.RUN.SUCCEEDED"
// The actor run has failed
ACTOR_RUN_FAILED = "ACTOR.RUN.FAILED"
// The actor run has timed out
ACTOR_RUN_TIMED_OUT = "ACTOR.RUN.TIMED_OUT"
// The actor run was aborted
ACTOR_RUN_ABORTED = "ACTOR.RUN.ABORTED"
// The actor run was resurrected
ACTOR_RUN_RESURRECTED = "ACTOR.RUN.RESURRECTED"
// The actor build was created
ACTOR_BUILD_CREATED = "ACTOR.BUILD.CREATED"
// The actor build has succeeded
ACTOR_BUILD_SUCCEEDED = "ACTOR.BUILD.SUCCEEDED"
// The actor build has failed
ACTOR_BUILD_FAILED = "ACTOR.BUILD.FAILED"
// The actor build has timed out
ACTOR_BUILD_TIMED_OUT = "ACTOR.BUILD.TIMED_OUT"
// The actor build was aborted
ACTOR_BUILD_ABORTED = "ACTOR.BUILD.ABORTED"
)
// MetaOrigin
const (
// """Possible origins for actor runs, i.e. how were the jobs started."""
// Job started from Developer console in Source section of actor
DEVELOPMENT = "DEVELOPMENT"
// Job started from other place on the website (either console or task detail page)
WEB = "WEB"
// Job started through API
API = "API"
// Job started through Scheduler
SCHEDULER = "SCHEDULER"
// Job started through test actor page
TEST = "TEST"
// Job started by the webhook
WEBHOOK = "WEBHOOK"
// Job started by another actor run
ACTOR = "ACTOR"
)

src/__main__.py

1import asyncio
2import logging
3
4from apify.log import ActorLogFormatter
5
6from .main import main
7
8# Set up logging of messages from the Apify SDK
9handler = logging.StreamHandler()
10handler.setFormatter(ActorLogFormatter())
11
12apify_client_logger = logging.getLogger('apify_client')
13apify_client_logger.setLevel(logging.INFO)
14apify_client_logger.addHandler(handler)
15
16apify_logger = logging.getLogger('apify')
17apify_logger.setLevel(logging.DEBUG)
18apify_logger.addHandler(handler)
19
20asyncio.run(main())

src/main.go

package main
import (
//"os"
"example/apify"
)
func main() {
input := apify.Actor.GetInput()
println( input )
}

src/main.py

1# Apify SDK - toolkit for building Apify Actors (Read more at https://docs.apify.com/sdk/python)
2from apify import Actor
3
4
5async def main():
6 async with Actor:
7 Actor.log.info('Hello from the Actor!')
8 # Write your code here

requirements.txt

1apify ~= 1.1.5